I need help with this program IN JAVA!! This project will be a Paint Calculator
ID: 3834712 • Letter: I
Question
I need help with this program IN JAVA!!
This project will be a Paint Calculator that gives the customer the area in square feet
to be painted. You will store the customer name, and details about each room in the customer’s
house. From that information, you will calculate the wall area of each room and a total for the
whole house. The data will need to be stored in a file so that you can retrieve information for
each customer’s paint requirements.
This project has these requirements:
1. Assume you are creating this program for a paying customer, and therefore it should
look, act, and be professional.
2. Assumptions: No more than 10 customers with a maximum of 4 rooms each. Make sure
your code is flexible and can handle 1-10 customers and each customer can have 1-4
rooms. The data will be written to and read from a file named: “CustomerData.txt”
3. It is assumed that all measurements are in feet and that each room is a rectangle with a
given height. Do not worry about areas in the room that would not be painted such as
ceiling, floor, doors, windows, etc.
4. All output must be formatted in a logical straightforward format. All input should have
proper prompts for the user and checking for valid input.
5. On start-up, the program should read in any existing data from the file
“CustomerData.txt”. You can only read from the file once at start-up and can only write
to the file when the user selects user item 2. “Save All Data”
6. You must use parallel arrays to store the data. (Extra Credit use an array of objects to store the data)
7. Data to be stored for each customer:
1. Customers Name
2. Room Name
3. Length of the room
4. Width of the room
5. Height of room
8. You must create a looping menu system resembling the following:
1. Create Customer – allow user input of all items in requirement 7 above. Input
must allow measurements in feet up to 1 decimal place i.e. Length = 6.5.
2. Save All Data
3. Print Customer Details – allow input of 1 customer name and print out the
customer name on 1 line then the details of each room including area on separate
lines. The final line should be the total area for the customer.
4. Print All Unique Customer Names
5. Delete Customer – input customer name and delete that customer’s data from the
file and current data in memory.
6. Extra Credit – Sort Data – sort the data by customer name and also sort the data
before it is stored in the file.
9. The program must be modular using at least 2 classes including 1 class that reads in and
takes care of the customer’s details and another class that deals with input/output from
the file IN JAVA!!
I
Explanation / Answer
import java.text.DecimalFormat; // to format numbers (check the documentation) import java.text.NumberFormat; /** * Calculates the amount of paint needed to paint a room * @author Helen Lawrence */ public class PaintShopCalculator { // Prices of the paint containers in dollars (constants) public final double FIVEGALLONS = 116.00; public final double ONEGALLON = 23.20; public final double HALFGALLON = 11.60; public final double QUART = 5.80; //4 quarts in a gallon public final double PINT = 2.90; //8 pints in a gallon public final double HALFPINT = 1.45; //16 half-pints in a gallon // Area that can be painted with one gallon of paint (in square inches) public final double AREA_PER_GALLON = 25000.0; /** * Initialize this PaintShopCalculator with the room measurements. For * example, if the height is 10'2'', heightFeet is 10 and heightInches is 2. * * @param heightFeet * the number of feet of the height measurement * @param heightInches * the number of inches of the height measurement * @param widthFeet * the number of feet of the width measurement * @param widthInches * the number of inches of the width measurement * @param lengthFeet * the number of feet of the length measurement * @param lengthInches * the number of inches of the length measurement */ //Instance fields public int a; //number of 5-gallon cans needed to paint the room public int b; //number of 1-gallon cans needed to paint the room public int c; //number of half-gallon cans needed to paint the room public int d; //number of quarts needed to paint the room public int e; //number of pints needed to paint the room public int f; //number of half-pints needed to paint the room double numGallons = 0; int room = 0; double price = 0; public PaintShopCalculator(int heightFeet, int heightInches, int lengthFeet, int lengthInches, int widthFeet, int widthInches) { int h = heightFeet*12 + heightInches; int l = lengthFeet*12 + lengthInches; int w = widthFeet*12 + widthInches; //opposite walls int walls = 2*(l*h) + 2*(w*h); //ceiling int ceiling = l*w; //total area to paint (in square inches) room = walls + ceiling; numGallons = (double)(room/AREA_PER_GALLON); } /** * Calculates how many cans of each size will be needed to paint the room */ public void PaintCanCalculator() { double remainder; a = (int)numGallons / 5; remainder = numGallons % 5; b = (int)(remainder / 1); remainder = remainder % 1; c = (int)(remainder / 0.5); remainder = remainder % 0.5; d = (int)(remainder / 0.25); remainder = remainder % 0.25; e = (int)(remainder / 0.125); remainder = remainder % 0.125; f = (int)(remainder / 0.0625); remainder = remainder % 0.0625; //if there is any remainder when the number of 1/2 pints are calculated //add an additional can to the total if(remainder != 0) { f +=1; } } /** * Calculates the total price of the paint cans needed to paint the room */ public void CalculatePrice(){ price = FIVEGALLONS*a + ONEGALLON*b + HALFGALLON*c + QUART*d + PINT*e + HALFPINT*f; } /** * Return as a string the result of the computation. The string lists * the exact amount of paint needed (with 3 digits after the decimal point), * the number and type of cans needed, and the price. * */ public String toString() { NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(3); NumberFormat mf = NumberFormat.getNumberInstance(); mf.setMaximumFractionDigits(2); PaintCanCalculator(); CalculatePrice(); String s = "You need " + nf.format(numGallons) + " gallons of paint " + " " +"You will need to purchase" + " " + showResult() + " " +"The total price is $" + mf.format(price) + " " + " " +"Thank you for your business!" ; return s; } /** * Shows the number of each type of paint can that the customer will need to purchase * @return String */ public String showResult() { String u = new String(); if(a !=0) { u = " " + a + " five-gallon can" + ((a != 1)?"s":"") + " "; } if(b != 0) { u += " " + b + " one-gallon can" + ((b != 1)?"s":"") + " "; } if(c != 0) { u += " " + c + " half-gallon can" + ((c != 1)?"s":"") + " "; } if(d != 0) { u += " " + d + " quart" + ((d != 1)?"s":"") + " "; } if(e != 0) { u += " " + e + " pint" + ((e != 1)?"s":"") + " "; } if(f != 0) { u += " " + f + " half-pint" + ((f != 1)?"s":"") + " "; } return u; } }