Question
Write a program that calculates the cost to send packages within the US. There are 3
different ways to send a package:
1. with UPS.
The cost to send a package with UPS is specified as follows:
Rate = $0.45 * number of pounds.
2. with US Mail.
The cost to send a package with US Mail is specified as follows:
If the weight is less than 3 pound, then the cost is $1.00.
If the weight is larger than 3 pounds, then the cost is $0.55 per pound.
3. with FedEx.
The cost to send a package with FedEx Mail depends on the zone where you send the
package to and is specified as follows:
Total cost in dollars = zone * number of pounds where zone is specified as follows:
Zone = 0.35 for IA, MT, OR and CA
Zone = 0.30 for TX, and UT
Zone = 0.55 for FL, MA and OH
Zone = 0.43 for all others
The program should ask the user for a number of packages. For every package the user
enters the package description, the weight and the zone. The program then calculates
for every package the lowest price, and prints this to the screen together with the carrier
name.
Example output:
Baby stroller $20.00 FedEx
Computer monitor $23.80 US Mail
Modem $5.60 US Mail
Make sure you program is open for extension, but closed for change.
You succeeded in this lab when you can add a new carrier (for example DHL) without
much code change, only code extension.
Also make sure you program to interfaces, rather than implementation.
Answer:
This is the class diagram of the problem. There may be others also as there is no one fixed method.
Hi Rajan, Please can u share the java code for the above class diagram
ReplyDeleteThere is no option to upload file here.
Delete