Você está na página 1de 3

CPT 237 Assignment zero

The purpose of this assignment is simply to get you going in case you forgot how to program
over the break. It should be a review of creating classes, reading input from the user and calling
a few methods your own class. Note, there are other ways to accomplish the desired task, but for
this assignment I want you to carefully follow the instructions given here.
The program is to determine how much it will cost to ship an item. This cost will be based on
the item’s weight, destination and the method of shipping. There will be three classes, a Package
class, a Shipper class and a MainClass. The Package class represents some particular item that is
to be shipped. The Shipper class represents the shipper. It simply estimates how much it will
cost to ship the given item. There will be three Shipper objects representing each the three types
of shipping that are offered. All output to the user should be in the MainClass. Neither the
Shipper nor the Package classes should have any I/O.
The rates for shipping are as follows:
Weight Standard 2nd day Express
1 to 8 1.50 2.50 8.00
9 to 16 2.00 4.00 17.00
17 and over 3.50 6.00 22.50

Create classes that match the following class descriptions.


Package Class
Data
Name Type Description
itemName String Type of the item
price double Price of this item
weight int Weight in pounds

Methods
Name Type Parameters Description
Package Name, price, weight Constructor sets all three member
variables
getItemName String none
getWeight int getter
getPrice double getter
Shipper Class
Data
Name Type Description
shippingType String One of ‘standard’, ‘second day’ or ‘express’
tierOneCost double Cost to ship less than 9 pounds
tierTwoCost double Cost to ship 9 through 16 pounds
tierThreeCost double Cost to ship 17 pounds or more
totalShipping double Total amount shipped by this shipper
totalPackages int Total number of packages shipped by this shipper

Methods
Name Type Parameters Description
Shipper method, tierOne, Constructor accepts the name of the shipping
tierTwo, tierThreemethod and the cost for each of the three tiers
of shipping
getShippingType String getter
getTotalShipping double getter
estimateShipping double Package pkg, zone Returns cost to ship the given package
addPackageShipping void Package pkg, zone Increments the totalShipped accumulator by
the amount it costs to ship this package to the
specified zone.

The estimateShipping method will accept a Package and a zone number as arguments. It
determines which of the tiers the weight of the package falls into and uses that value to make its
calculations. The calculations are as follows:
• zone one ships at the given tier;
• zone two adds 10% to the shipping rate for that tier
• zone three adds 20%
• zone four adds 30%;
• zone five adds 50%
For example, if a package weighing 9 pounds costs 3.00 to ship; it will cost 3.30 to ship to zone
two, 3.60 to ship to zone three, etc. Note that this method only calculates the value. It does not
modify the totalShipped variable. Note that shipping to zone five costs 50% more, not 40%.
The addPackageShipping method first determines the amount that it costs to ship the package
to the given zone. It then adds this amount to the totalShipped variable. It should also increment
the total number of packages shipped using this method.
The MainClass must have a static method, getOrder, which ask the user for the name of the
item, the price of the item, and the item’s weight. (In the real world, we would know the weight
and price, of course.) Using this information, it will then instantiate a Package object with the
given name and weight. This method has only the console (Scanner) as a parameter. It returns
the created Package object. The main method should have a Scanner object which it passes to
the getOrder method.
The main method will first create three Shipper objects, one each for standard, second day and
express shipping. It will then use a while loop that does the following:
1. call getOrder to retrieve a new Package object; note that the object is not created in
main method, but in getOrder
2. display the package name and the weight to the user
3. ask for the destination zone (1-5)
4. call the estimateShipping method in the each Shipper, passing in the Package object
and zone
5. display the method and cost of each shipping method
6. ask the user for the shipping method desired
7. call addPackageShipping to the appropriate Shipper object (based on the shipping method
selected by the user)
8. print the information for the order; do this in main, not the Shipper; the following should
be displayed:
o item, price, shipping, total (i.e. price plus shipping)
9. ask whether to enter another package
10. after the user indicates they want to stop (i.e., after the end of the while-loop), display the
method, count and total amount shipped for each of your Shipper objects
By this point in your coursework, your programming skills should be good enough to allow you
to format your output well. (The book has a discussion on printf in chapter four.) All integers
should be printed as integers…no decimal place. All monetary output should be exactly two
decimals. Things should line up nicely.
Make certain you submit a zipped eclipse project. The project name should include your last
name.

Você também pode gostar