Reference no: EM13167065
Package-delivery services, such as FedEx, DHL and UPS, offer a number of different shipping options, each with specific costs associated.
Create an inheritance hierarchy containing super class Package and subclasses RegularPackage, TwoDayPackage and OvernightPackage.
a. Super class Package.java
- It includes data members representing the package id, first and last name for both the sender and the recipient of the package (in fact, address, city, state and ZIP code for both the sender and the recipient should be included).
- It includes data members that store the weight (in ounces) and cost per ounce to ship the package.
- Package's constructors should initialize these data members. Ensure that the weight and cost per ounce contain positive values.
- Package should provide an abstract public method calculateCost() that is supposed to return a double indicating the cost associated with shipping the package.
- (Don't forget to include toString, accessors, and mutators).
b. Subclass RegularPackage.java
- It inherits the functionality of super Package, but also includes an additional data member that represents a rate that the shipping company uses for calculating the cost of regular package.
- The constructors should initialize data members. Ensure that the rate is validated before being set.
- It should override calculateCost() method so that it computes the shipping cost by multiplying the rate with the weight-based cost.
c. Subclass TwoDayPackage.java
- It inherits the functionality of super class Package, but also includes a data member that represents a flat fee that the shipping company charges for two-day delivery service.
- The constructors should initialize all data members. Ensure that the flat fee is validated before being set.
- It should override method calculateCost() so that it computes the shipping cost by adding the flat fee to the weight-based cost.
d. Subclass OvernightPackage.java
- It inherits the functionality of super class Package and contains an additional data member representing an additional fee per ounce charged for overnight-delivery service.
- The constructors should initialize data members. Ensure that the fee is validated before being set.
- It should override method calculateCost() so that it adds the additional fee per ounce to the standard cost per ounce before calculating the shipping cost.
e. Write a client program that simulates a package delivery system.
- The program should contain an array of Package to hold variety of objects of RegularPackage, TwoDayPackage and OvernightPackage.
- It loops through the array to process the packages polymorphically.
- It should be menu-driven, use a menu to do the following.
1: To create a regular package object and put it into the array of Package.
2: To create a two-day package object and put it into the array of Package.
3: To create an overnight package object and put it into the array of Package.
4: To display a report that shows all the packages' information in the array using polymorphism.
5: To display the total shipping cost for all the packages in the array.
0: To end program