You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
3.6 KiB

package cmpt213.assignment3.packagedeliveries.control;
import cmpt213.assignment3.packagedeliveries.model.BookPackage;
import cmpt213.assignment3.packagedeliveries.model.ElectronicPackage;
import cmpt213.assignment3.packagedeliveries.model.PackageInfo;
import cmpt213.assignment3.packagedeliveries.model.PerishablePackage;
import java.time.LocalDateTime;
/**
* The PackageFactory class is a factory class that creates a package object based on the type of
* package that is passed in
*/
public class PackageFactory {
/**
* > This function creates a new package object based on the package type
*
* @param type The type of package.
* @param name The name of the package.
* @param notes A string of notes about the package.
* @param price The price of the package
* @param weight The weight of the package in kilograms
* @param delivered Whether or not the package has been delivered
* @param expectDate The date the package is expected to be delivered.
* @param author The author of the book.
* @param expiryDate The date the package expires.
* @param handlingFee The handling fee for the package.
* @return A new instance of the package type.
*/
public static PackageInfo create(PackageType type, String name, String notes, double price, double weight, boolean delivered, LocalDateTime expectDate, String author, LocalDateTime expiryDate, double handlingFee) {
return type.getInstance(name, notes, price, weight, delivered, expectDate, author, expiryDate, handlingFee);
}
// Creating an enum called PackageType.
public enum PackageType {
Book {
public PackageInfo getInstance(String name, String notes, double price, double weight, boolean delivered, LocalDateTime expectedDate, String author, LocalDateTime expiryDate, double handlingFee) {
return new BookPackage(name, notes, price, weight, delivered, expectedDate, author);
}
},
Perishable {
public PackageInfo getInstance(String name, String notes, double price, double weight, boolean delivered, LocalDateTime expectedDate, String author, LocalDateTime expiryDate, double handlingFee) {
return new PerishablePackage(name, notes, price, weight, delivered, expectedDate, expiryDate);
}
},
Electronic {
public PackageInfo getInstance(String name, String notes, double price, double weight, boolean delivered, LocalDateTime expectedDate, String author, LocalDateTime expiryDate, double handlingFee) {
return new ElectronicPackage(name, notes, price, weight, delivered, expectedDate, handlingFee);
}
};
/**
* It returns a PackageInfo object.
*
* @param name The name of the package.
* @param notes a string that describes the package
* @param price The price of the package
* @param weight the weight of the package in kg
* @param delivered true if the package has been delivered, false otherwise
* @param expectedDate The date the package is expected to be delivered.
* @param author The name of the author of the book.
* @param expiryDate The date when the package expires.
* @param handlingFee The handling fee for the package.
* @return A package object
*/
public abstract PackageInfo getInstance(String name, String notes, double price, double weight, boolean delivered, LocalDateTime expectedDate, String author, LocalDateTime expiryDate, double handlingFee);
}
}