(15 points)
In this assignment, you will practice doing the following:
A very good friend of yours owns a shop that sells paint. Typically, a customer comes to her shop with the dimensions of the room that the customer wants to paint. The customer wants to know how much paint is needed and how much it will cost. Up to now, your friend was doing a computation on paper to answer the customer's questions. However, she would like to use a computer to make the process faster. She has heard about your prowess as a programmer and asked you to write a program that would answer the customer's questions. You are flattered and excited and start thinking about the algorithm.
The details
This is how the problem can be solved on paper.
The customer gives you the height, width and length of the room. We will assume that the customer paints the walls and ceiling of the room. The floor is not painted. Your friend told you that one gallon of paint can cover 25000 square inches.
It is then fairly straighforward to find the amount of paint required. For instance, a room 15 feet long, 10 feet wide and 8 feet high has an area equal to 550 square feet for the walls and ceiling. This is 79200 square inches. It requires 3.168 gallons of paint.
But paint comes in containers of different sizes: 5 gallons, 1 gallon, half gallon, quart, pint and half pint. The next step is to break down the required paint amount between all of these sizes. When doing so, try to get as close as possible to the required amount of paint.
For instance, for 3.168 gallons, one needs 3 one gallon containers, 1 one pint container and 1 half pint container which gives a total of 3.1875 gallons.
To compute the total price use the following price list:
- 5 gallons: $116.00
- 1 gallon: $23.20
- 1/2 gallon: $11.60
- quart: $5.80
- pint: $2.90
- half pint: $1.45
What to do
Download the two classes making up this assignment: PaintShop.java and PaintShopCalculator.java, and include them in an Eclipse project. The main method is in the PaintShop class. To run the code, select the PaintShop class and click Run. You should see a window that allows the user to enter the room measurements. If you click the Calculate button, you should get the string "Thank you for your business" in the text area at the bottom of the window. When your code is complete, the text area will display the amount of paint needed.
The class PaintShop.java is complete. Don't change it. It constructs the GUI that allows the user to enter the room dimensions and displays the result of the paint computation. You can read through the code. However, you don't need to understand any of it for this assignment. This code is beyond CSC 142 (Though not difficult, it requires some knowledge of the Sun libraries).
The class PaintShopCalculator.java is in charge of computing the amount of paint needed. As given, this class is mostly empty. It lists a few constants, and the signatures of its two public methods, namely the constructor that receives the room dimensions, and a toString method that returns the result of the computation in a string. You need to complete it following good programming practices (comments, use of private methods where needed, use of constants etc...).
The string returned by toString should list the exact amount of paint needed (with 3 digits after the decimal point), the number and type of paint containers needed, and the price (with 2 digits after the decimal point). Pay attention to the spelling (container versus containers), and the quality of the output (no 0 one gallon container). Below in an example of such a string as seen with the GUI (another example is given within the code as a comment before the toString method). List the containers in the same order as in this example. Note also that the string is not formatted by the GUI. It will appear exactly as you format it within your toString method.
