Erinevus lehekülje "ITI0011:harjutus 10" redaktsioonide vahel
(→Mall) |
|||
12. rida: | 12. rida: | ||
* Tavaliste pakkide puhul arvestada ainult klientide summaarset prioriteeti. | * Tavaliste pakkide puhul arvestada ainult klientide summaarset prioriteeti. | ||
− | == Mall == | + | === Mall === |
Package.java | Package.java | ||
<source lang="java"> | <source lang="java"> |
Redaktsioon: 15. märts 2016, kell 00:02
Ü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.