Homework 3 

(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 79200 / 25000 = 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.

It is also important that the total number of containers be as small as possible. For example, your program should not display "2 half-pint containers" since two half pints make a pint.

For instance, for 3.168 gallons, one needs 3 one-gallon containers, 1 one-pint container and 1 one-half-pint container which gives a total of 3.1875 gallons.

To compute the total price use the following price list:

  • 5 gallons: $124.00
  • 1 gallon: $25.10
  • 1/2 gallon: $13.00
  • quart: $6.70
  • pint: $3.95
  • half pint: $2.25

Moreover, the customer has the possibility of getting a discount. If the amount of cents in the total price is odd and divisible by 5, then one of the largest containers is given for free to the customer. In the above example, the customer is buying 3 one-gallon containers, 1 one-pint container and 1 one-half-pint of paint, the cost is 3 x 25.10 + 3.95 + 2.25 = $81.50. The amount of cents in the total is 50c. Since 50 is even, the customer is not eligible for a discount. However, if for some other example, the customer were to buy 3 five-gallon containers and 1 one-pint container of paint, the cost would be 3x124 + 3.95 = $375.95. The amount of cents is 95c which is divisible by 5 and is odd, therefore the customer would get one of the largest container for free which is here one five-gallon container. Their cost would become 2 x 124 + 3.95 = $251.95.

 

What to do

Download the two classes making up this assignment: PaintShop.java and PaintShopCalculator.java, and include them in an Eclipse project. Run the code by clicking the Run button while the PaintShop file is open. 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 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 Java libraries.

The class PaintShopCalculator 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...). Also, this assignment is to practice what we have seen in class through the topic of conditionals. In particular, your solution should not use loops or arrays.

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 (don't display in the list of containers any container whose number is 0). 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.


Your program has to be your own.