Class PackageBase
java.lang.Object
cmpt213.assignment4.packagedeliveries.webappserver.model.PackageBase
- All Implemented Interfaces:
Package,Comparable<PackageBase>
- Direct Known Subclasses:
Book,Electronic,Perishable
Abstract package base class that is modelled after a package; stores name, notes, price, weight, date,
and delivery status. Must be implemented as: Book, Perishable, or Electronic.
Implements the Package Interface.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final DateTimeFormatterprotected final LocalDateTimeprotected booleanprotected final Stringprotected final Stringprotected final doubleprotected final double -
Constructor Summary
ConstructorsConstructorDescriptionPackageBase(String name, String notes, double price, double weight, LocalDateTime expectedDeliveryDate) Constructor for class, creates an object modelled as a package with its respective fields. -
Method Summary
Modifier and TypeMethodDescriptionintSorts arraylist of package base items based on delivery date.Gets the delivery date of the package as a LocalDateTime object.getName()Gets the name of the package.getNotes()Gets the notes of the package.doublegetPrice()Gets the price of the package.doubleGets the weight of the package.booleanGets the package's delivery status; returns false if not delivered, true if delivered.voidsetDeliveryStatus(boolean newStatus) Changes a package's delivery status; either true or false.
-
Field Details
-
dateFormat
-
name
-
notes
-
price
protected final double price -
weight
protected final double weight -
expectedDeliveryDate
-
isDelivered
protected boolean isDelivered
-
-
Constructor Details
-
PackageBase
public PackageBase(String name, String notes, double price, double weight, LocalDateTime expectedDeliveryDate) Constructor for class, creates an object modelled as a package with its respective fields.- Parameters:
name- The name of the package, cannot be empty.notes- Any notes for the package, can be empty.price- The price (in CAD) of the package, cannot be negative.weight- The weight (in kg) of the package, cannot be negative.expectedDeliveryDate- The date of the package (Year, Month, Day, Hour, Minute), in 24-hour format.
-
-
Method Details
-
compareTo
Sorts arraylist of package base items based on delivery date. Order: oldest to newest. Implementation ofPackage.compareTo(PackageBase)- Specified by:
compareToin interfaceComparable<PackageBase>- Specified by:
compareToin interfacePackage- Parameters:
p- the object to be compared.- Returns:
- An integer, positive if date is before current time, negative if after.
-
isDelivered
public boolean isDelivered()Gets the package's delivery status; returns false if not delivered, true if delivered. Implementation ofPackage.isDelivered()- Specified by:
isDeliveredin interfacePackage- Returns:
- A boolean value (true or false)
-
setDeliveryStatus
public void setDeliveryStatus(boolean newStatus) Changes a package's delivery status; either true or false. Implementation ofPackage.setDeliveryStatus(boolean)- Specified by:
setDeliveryStatusin interfacePackage- Parameters:
newStatus- The new status of the package, boolean value.
-
getExpectedDeliveryDate
Gets the delivery date of the package as a LocalDateTime object. Implementation ofPackage.getExpectedDeliveryDate()- Specified by:
getExpectedDeliveryDatein interfacePackage- Returns:
- A LocalDateTime object with the date information.
-
getName
Gets the name of the package. Implementation ofPackage.getName() -
getNotes
Gets the notes of the package. Implementation ofPackage.getNotes() -
getPrice
public double getPrice()Gets the price of the package. Implementation ofPackage.getPrice() -
getWeight
public double getWeight()Gets the weight of the package. Implementation ofPackage.getWeight()
-