Erinevus lehekülje "ITI0011:harjutus 10" redaktsioonide vahel
(→Mall) |
|||
7. rida: | 7. rida: | ||
Tundmatu logistikakeskus on sattunud seni nägemata probleemi otsa, nimelt tuli firma omanikelt idee luua priotiseeritud pakisüsteemi, mis saadab pakke vastavalt logistikakekuse poolt määratud järjekorrale. Idee oli määratud parendama tähtsate klientide rahololu transporditeenusega. Paraku on süsteem ööpäevaringselt töös ning ümberkirjutamine on antud fintantstingimustes võimatu. Firma peaarhitekti poolt tuli ettepanek laiendada süsteemi standardpakke ja vahetada iga logistikakeskuse väljastusautomaadi PackageProvider uue vastu nii, et oleks täidetud järgmised tingimused: | Tundmatu logistikakeskus on sattunud seni nägemata probleemi otsa, nimelt tuli firma omanikelt idee luua priotiseeritud pakisüsteemi, mis saadab pakke vastavalt logistikakekuse poolt määratud järjekorrale. Idee oli määratud parendama tähtsate klientide rahololu transporditeenusega. Paraku on süsteem ööpäevaringselt töös ning ümberkirjutamine on antud fintantstingimustes võimatu. Firma peaarhitekti poolt tuli ettepanek laiendada süsteemi standardpakke ja vahetada iga logistikakeskuse väljastusautomaadi PackageProvider uue vastu nii, et oleks täidetud järgmised tingimused: | ||
− | * Väljastusautomaat eelistab alati PremiumPackage tüüpi pakke | + | * Väljastusautomaat eelistab alati <code>PremiumPackage</code> tüüpi pakke |
− | * | + | * <code>PremiumPackage</code> pakkidest tuleb eelistada '''kõrgema prioriteediga''' (suurema <code>priority</code> väärtusega pakk) |
− | * Kui kaks PremiumPackage tüüpi pakki omavad sama prioriteeti, siis tuleb arvestada klientide summaarset prioriteeti (receiver.priority + sender.priority). Identsete prioriteetidega pakke ei järjestata (vahet pole, kumb enne väljastatakse) | + | * Kui kaks <code>PremiumPackage</code> tüüpi pakki omavad sama prioriteeti, siis tuleb arvestada klientide '''summaarset prioriteeti''' (<code>receiver.priority + sender.priority</code>). Identsete prioriteetidega pakke ei järjestata (vahet pole, kumb enne väljastatakse) |
* Tavaliste pakkide puhul arvestada ainult klientide summaarset prioriteeti. | * Tavaliste pakkide puhul arvestada ainult klientide summaarset prioriteeti. | ||
15. rida: | 15. rida: | ||
Package.java | Package.java | ||
<source lang="java"> | <source lang="java"> | ||
+ | /** | ||
+ | * Package class. | ||
+ | */ | ||
public class Package { | public class Package { | ||
− | + | /** | |
− | + | * Package number printed on page. | |
− | + | */ | |
− | + | protected String packageNumber; | |
− | + | /** | |
− | + | * Package width in cm. | |
− | + | */ | |
+ | protected int width; | ||
+ | /** | ||
+ | * Package height in cm. | ||
+ | */ | ||
+ | protected int height; | ||
+ | /** | ||
+ | * Package sender. | ||
+ | */ | ||
+ | protected Customer sender; | ||
+ | /** | ||
+ | * Package receiver. | ||
+ | */ | ||
+ | protected Customer receiver; | ||
+ | /** | ||
+ | * Get receiver. | ||
+ | * | ||
+ | * @return Receiver customer | ||
+ | */ | ||
public Customer getReceiver() { | public Customer getReceiver() { | ||
return receiver; | return receiver; | ||
} | } | ||
+ | /** | ||
+ | * Package cunstroctor without arguments. | ||
+ | */ | ||
+ | public Package() { | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Package constructor. | ||
+ | * | ||
+ | * @param packageNumber Package number printed on package | ||
+ | * @param width Package width in cm | ||
+ | * @param height Package height in cm | ||
+ | */ | ||
+ | public Package(String packageNumber, int width, int height) { | ||
+ | this.packageNumber = packageNumber; | ||
+ | this.width = width; | ||
+ | this.height = height; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Set receiver. | ||
+ | * | ||
+ | * @param receiver Receiver customer | ||
+ | */ | ||
public void setReceiver(Customer receiver) { | public void setReceiver(Customer receiver) { | ||
this.receiver = receiver; | this.receiver = receiver; | ||
} | } | ||
+ | /** | ||
+ | * Get sender. | ||
+ | * | ||
+ | * @return Sender customer | ||
+ | */ | ||
public Customer getSender() { | public Customer getSender() { | ||
return sender; | return sender; | ||
} | } | ||
+ | /** | ||
+ | * Set sender. | ||
+ | * | ||
+ | * @param sender Sender customer | ||
+ | */ | ||
public void setSender(Customer sender) { | public void setSender(Customer sender) { | ||
this.sender = sender; | this.sender = sender; | ||
} | } | ||
− | + | /** | |
− | + | * Get package number. | |
− | + | * | |
− | + | * @return Package number | |
− | + | */ | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
public String getPackageNumber() { | public String getPackageNumber() { | ||
return packageNumber; | return packageNumber; | ||
} | } | ||
+ | /** | ||
+ | * Set package number | ||
+ | * | ||
+ | * @param packageNumber Package number | ||
+ | */ | ||
public void setPackageNumber(String packageNumber) { | public void setPackageNumber(String packageNumber) { | ||
this.packageNumber = packageNumber; | this.packageNumber = packageNumber; | ||
} | } | ||
+ | /** | ||
+ | * Get package height. | ||
+ | * | ||
+ | * @return Package height | ||
+ | */ | ||
public int getHeight() { | public int getHeight() { | ||
return height; | return height; | ||
} | } | ||
+ | /** | ||
+ | * Set package height. | ||
+ | * | ||
+ | * @param height Package height. | ||
+ | */ | ||
public void setHeight(int height) { | public void setHeight(int height) { | ||
this.height = height; | this.height = height; | ||
} | } | ||
+ | /** | ||
+ | * Get package width. | ||
+ | * | ||
+ | * @return Package width. | ||
+ | */ | ||
public int getWidth() { | public int getWidth() { | ||
return width; | return width; | ||
} | } | ||
+ | /** | ||
+ | * Get package width. | ||
+ | * | ||
+ | * @param width Package width. | ||
+ | */ | ||
public void setWidth(int width) { | public void setWidth(int width) { | ||
this.width = width; | this.width = width; | ||
} | } | ||
+ | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
</source> | </source> | ||
94. rida: | 155. rida: | ||
Customer.java | Customer.java | ||
<source lang="java"> | <source lang="java"> | ||
+ | /** | ||
+ | * Customer class. | ||
+ | */ | ||
public class Customer { | public class Customer { | ||
+ | /** | ||
+ | * Customer priority. | ||
+ | * 0 < priority < 1000 | ||
+ | */ | ||
private int priority; | private int priority; | ||
+ | /** | ||
+ | * Customer name. | ||
+ | */ | ||
private String name; | private String name; | ||
+ | /** | ||
+ | * Customer address. | ||
+ | */ | ||
private String address; | private String address; | ||
− | + | /** | |
− | + | * Customer constructor without arguments. | |
− | + | */ | |
− | public Customer( | + | public Customer() { |
− | |||
} | } | ||
− | public Customer(String name | + | /** |
+ | * Customer constructor. | ||
+ | * | ||
+ | * @param priority Customer prority | ||
+ | * @param name Customer name | ||
+ | * @param address Customer address | ||
+ | */ | ||
+ | public Customer(int priority, String name, String address) { | ||
+ | this.priority = priority; | ||
this.name = name; | this.name = name; | ||
− | |||
this.address = address; | this.address = address; | ||
} | } | ||
− | |||
− | |||
− | |||
+ | /** | ||
+ | * Get customer address. | ||
+ | * | ||
+ | * @return Customer address | ||
+ | */ | ||
public String getAddress() { | public String getAddress() { | ||
return address; | return address; | ||
} | } | ||
− | + | /** | |
+ | * Set customer address. | ||
+ | * | ||
+ | * @param address Customer address | ||
+ | */ | ||
public void setAddress(String address) { | public void setAddress(String address) { | ||
this.address = address; | this.address = address; | ||
} | } | ||
+ | /** | ||
+ | * Get customer name. | ||
+ | * | ||
+ | * @return Customer name | ||
+ | */ | ||
public String getName() { | public String getName() { | ||
return name; | return name; | ||
} | } | ||
+ | /** | ||
+ | * Set customer name. | ||
+ | * | ||
+ | * @param name Customer name | ||
+ | */ | ||
public void setName(String name) { | public void setName(String name) { | ||
this.name = name; | this.name = name; | ||
} | } | ||
+ | /** | ||
+ | * Get customer priority. | ||
+ | * | ||
+ | * @return Customer priority | ||
+ | */ | ||
public int getPriority() { | public int getPriority() { | ||
return priority; | return priority; | ||
} | } | ||
+ | |||
+ | /** | ||
+ | * Set customer priority | ||
+ | * | ||
+ | * @param priority Customer priority | ||
+ | */ | ||
public void setPriority(int priority) { | public void setPriority(int priority) { | ||
this.priority = priority; | this.priority = priority; | ||
} | } | ||
} | } | ||
+ | |||
+ | |||
</source> | </source> | ||
145. rida: | 254. rida: | ||
<source lang="java"> | <source lang="java"> | ||
import java.util.List; | import java.util.List; | ||
+ | |||
+ | /** | ||
+ | * PackageProvider interface. | ||
+ | */ | ||
public interface PackageProvider { | public interface PackageProvider { | ||
− | + | /** | |
+ | * Get next package in the queue. | ||
+ | * | ||
+ | * @return Next package | ||
+ | */ | ||
+ | Package getNextPackage(); | ||
− | + | /** | |
+ | * Add new package to queue. | ||
+ | * | ||
+ | * @param packageToAdd A new package to add | ||
+ | */ | ||
+ | void addPackage(Package packageToAdd); | ||
− | + | /** | |
+ | * Returns whether the provider hax next package or not. | ||
+ | * | ||
+ | * @return next package exists | ||
+ | */ | ||
+ | boolean hasNextPackage(); | ||
− | + | /** | |
+ | * Set package filter to queue. | ||
+ | * | ||
+ | * @param packageFilter PackageFilter | ||
+ | */ | ||
+ | void setPackageFilter(PackageFilter packageFilter); | ||
− | + | /** | |
+ | * Get package filter. | ||
+ | * | ||
+ | * @return packageFilter | ||
+ | */ | ||
+ | PackageFilter getPackageFilter(); | ||
+ | |||
+ | /** | ||
+ | * Get packages as list (not ordered). | ||
+ | * | ||
+ | * @return Package list | ||
+ | */ | ||
+ | List<Package> getPackages(); | ||
+ | |||
+ | /** | ||
+ | * Get all sender packages (not ordered). | ||
+ | * | ||
+ | * @param customer Sender customer | ||
+ | * @return Ordered list of sender packages | ||
+ | */ | ||
+ | List<Package> findAllPackagesBySender(Customer customer); | ||
+ | |||
+ | /** | ||
+ | * Get all reciever packages (not ordered). | ||
+ | * | ||
+ | * @param customer Receiver customer | ||
+ | * @return Ordered list of receiver packages | ||
+ | */ | ||
+ | List<Package> findAllPackagesByReceiver(Customer customer); | ||
} | } | ||
+ | |||
</source> | </source> | ||
Redaktsioon: 15. märts 2016, kell 00:01
Üldine
Ülesande kaitsmised: 16. - 18. märts
Kaust gitis: EX10
Ülesanne
Tundmatu logistikakeskus on sattunud seni nägemata probleemi otsa, nimelt tuli firma omanikelt idee luua priotiseeritud pakisüsteemi, mis saadab pakke vastavalt logistikakekuse poolt määratud järjekorrale. Idee oli määratud parendama tähtsate klientide rahololu transporditeenusega. Paraku on süsteem ööpäevaringselt töös ning ümberkirjutamine on antud fintantstingimustes võimatu. Firma peaarhitekti poolt tuli ettepanek laiendada süsteemi standardpakke ja vahetada iga logistikakeskuse väljastusautomaadi PackageProvider uue vastu nii, et oleks täidetud järgmised tingimused:
- Väljastusautomaat eelistab alati
PremiumPackage
tüüpi pakke PremiumPackage
pakkidest tuleb eelistada kõrgema prioriteediga (suuremapriority
väärtusega pakk)- Kui kaks
PremiumPackage
tüüpi pakki omavad sama prioriteeti, siis tuleb arvestada klientide summaarset prioriteeti (receiver.priority + sender.priority
). Identsete prioriteetidega pakke ei järjestata (vahet pole, kumb enne väljastatakse) - Tavaliste pakkide puhul arvestada ainult klientide summaarset prioriteeti.
Mall
Package.java <source lang="java"> /**
* Package class. */
public class Package {
/** * Package number printed on page. */ protected String packageNumber; /** * Package width in cm. */ protected int width; /** * Package height in cm. */ protected int height; /** * Package sender. */ protected Customer sender; /** * Package receiver. */ protected Customer receiver;
/** * Get receiver. * * @return Receiver customer */ public Customer getReceiver() { return receiver; }
/** * Package cunstroctor without arguments. */ public Package() { }
/** * Package constructor. * * @param packageNumber Package number printed on package * @param width Package width in cm * @param height Package height in cm */ public Package(String packageNumber, int width, int height) { this.packageNumber = packageNumber; this.width = width; this.height = height; }
/** * Set receiver. * * @param receiver Receiver customer */ public void setReceiver(Customer receiver) { this.receiver = receiver; }
/** * Get sender. * * @return Sender customer */ public Customer getSender() { return sender; }
/** * Set sender. * * @param sender Sender customer */ public void setSender(Customer sender) { this.sender = sender; }
/** * Get package number. * * @return Package number */ public String getPackageNumber() { return packageNumber; }
/** * Set package number * * @param packageNumber Package number */ public void setPackageNumber(String packageNumber) { this.packageNumber = packageNumber; }
/** * Get package height. * * @return Package height */ public int getHeight() { return height; }
/** * Set package height. * * @param height Package height. */ public void setHeight(int height) { this.height = height; }
/** * Get package width. * * @return Package width. */ public int getWidth() { return width; }
/** * Get package width. * * @param width Package width. */ public void setWidth(int width) { this.width = width; }
}
</source>
Customer.java <source lang="java"> /**
* Customer class. */
public class Customer {
/** * Customer priority. * 0 < priority < 1000 */ private int priority; /** * Customer name. */ private String name; /** * Customer address. */ private String address;
/** * Customer constructor without arguments. */ public Customer() { }
/** * Customer constructor. * * @param priority Customer prority * @param name Customer name * @param address Customer address */ public Customer(int priority, String name, String address) { this.priority = priority; this.name = name; this.address = address; }
/** * Get customer address. * * @return Customer address */ public String getAddress() { return address; }
/** * Set customer address. * * @param address Customer address */ public void setAddress(String address) { this.address = address; }
/** * Get customer name. * * @return Customer name */ public String getName() { return name; }
/** * Set customer name. * * @param name Customer name */ public void setName(String name) { this.name = name; }
/** * Get customer priority. * * @return Customer priority */ public int getPriority() { return priority; }
/** * Set customer priority * * @param priority Customer priority */ public void setPriority(int priority) { this.priority = priority; }
}
</source>
PackageProvider.java <source lang="java"> import java.util.List;
/**
* PackageProvider interface. */
public interface PackageProvider {
/** * Get next package in the queue. * * @return Next package */ Package getNextPackage();
/** * Add new package to queue. * * @param packageToAdd A new package to add */ void addPackage(Package packageToAdd);
/** * Returns whether the provider hax next package or not. * * @return next package exists */ boolean hasNextPackage();
/** * Set package filter to queue. * * @param packageFilter PackageFilter */ void setPackageFilter(PackageFilter packageFilter);
/** * Get package filter. * * @return packageFilter */ PackageFilter getPackageFilter();
/** * Get packages as list (not ordered). * * @return Package list */ List<Package> getPackages();
/** * Get all sender packages (not ordered). * * @param customer Sender customer * @return Ordered list of sender packages */ List<Package> findAllPackagesBySender(Customer customer);
/** * Get all reciever packages (not ordered). * * @param customer Receiver customer * @return Ordered list of receiver packages */ List<Package> findAllPackagesByReceiver(Customer customer);
}
</source>
Lisaosa (0.5p)
Sageli satub pakiringlusesse pakke, mis ei vasta ettevõtte poolt ettekirjuatud nõudmistele. Implementeerida PackageFilter alusel PackageProviderisse sisendfilter, mis kontrollib pakkide valiidsust. Kõik pakid peavad vastama tingimustele:
- Receiver, sender ei ole tühi, receiveril on nimi (mitte tühistring) koos prioriteediga, mis on suurem kui null.
- Kõrgus ja laius on rangelt nullist suuremad ja 1000 (väljaarvatud) väiksem
- Receiver ei ühti senderiga
PremiumPackage puhul
- Priority rangelt suurem kui null.