Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //A painting company has determined that for every 115 square feet of wall space, one gallon of paint and eight hours of labor.
- //i made a method that returns the validated double the real validation is just the while loop
- import java.util.Scanner;
- public class PaintJob {
- private static int SizeToCost = 115;
- private static int PaintToCost = 1;
- private static int LabourToCost = 8;
- private static int LabourCostPerHour = 18;
- public static void main(String[] args)
- { //previous code simplified + validation
- double RoomSize= getDoubleWithValidation("Enter size of each room (in squared feet): ");
- double PaintCost = getDoubleWithValidation("Enter price of paint per gallon: ");
- double RoomCount = getDoubleWithValidation("Enter number of rooms to paint: ");
- double RoomCostUnit = (RoomSize * RoomCount) / SizeToCost;
- double PaintCountTotal = PaintToCost * RoomCostUnit;
- double LabourCountTotal = LabourToCost * RoomCostUnit;
- double PaintCostTotal = PaintCountTotal * PaintCost;
- double LabourCostTotal = LabourCountTotal * LabourCostPerHour;
- double JobCostTotal = PaintCostTotal + LabourCostTotal;
- double DisplayPaintCountTotal = (double)((int)(PaintCountTotal * 100) / 100.0);
- double DisplayLabourCountTotal = (double)((int)(LabourCountTotal * 100) / 100.0);
- double DisplayPaintCostTotal = (double)((int)(PaintCostTotal * 100) / 100.0);
- double DisplayLabourCostTotal = (double)((int)(LabourCostTotal * 100) / 100.0);
- double DisplayJobCostTotal = (double)((int)(JobCostTotal * 100) / 100.0);
- String Message = "The number of gallons of paint required = " + DisplayPaintCountTotal + "\n" +
- "The hours of labor required = " + DisplayLabourCountTotal + "\n" +
- "The cost of the paint = " + DisplayPaintCostTotal + "\n" +
- "The labor charges = " + DisplayLabourCostTotal + "\n" +
- "The total cost of the paint job = " + DisplayJobCostTotal + "\n";
- System.out.println(Message);
- }
- public static double getDoubleWithValidation(String msg) {
- double temp = 0;
- Scanner s = new Scanner(System.in);//make object of scanner
- System.out.println(msg);//prints msg
- temp = s.nextDouble(); //gets the double
- while(temp<=0) { // validation
- System.out.println("Please, the number must be higher than 0");
- temp = s.nextDouble();
- }
- //s.close(); // dont close scanner object here
- return temp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment