CS 117: Introduction to Computer Science
Assignment 4: Coffee Bags

Assigned on Monday, 1/14/02.
Due on Wednesday, 1/16/02, electronically, by 9 PM.

Java Coffee Outlet runs a catalog business selling one type of rare coffee. The company sells the coffee in 2-lb bags only, and the price of a single 2-lb bag is $5.50. When a customer places an order, the company ships the order in boxes. The boxes come in three sizes: the large box holds 20 2-lb bags, the medium 10 bags, and the small 5 bags. The cost of a large box is $2.00, a medium box is $1.00, and a small box $0.50. The order is shipped using the least number of boxes with the cheapest cost. For example, the order of 25 bags will be shipped in two boxes, one large and one small. Write a class called CoffeeBags whose main method computes the total cost of an order. Use InputBox to accept the number of bags for an order and OutputBox to display the total cost including the cost of boxes. Display the output in the following format:



Number of Bags Ordered:  52 - $ 286.
            Boxes Used:
                      2 Large  - $4.
                      1 Medium - $1.
                      1 Small  - $.5

    Your total cost is: $ 291.5



Remember that you can format a double value x to two decimal places by the expression
    Math.round(x * 100) / 100.0

Good luck!

Assignment from C. Thomas Wu, An Introduction to Object Oriented Programming With Java, McGraw-Hill, 2001.