VerdommeMan

Step 2 fix

Aug 27th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.48 KB | None | 0 0
  1. //A painting company has determined that for every 115 square feet of wall space, one gallon of paint and eight hours of labor.
  2.  
  3. //i made a method that returns the validated double the real validation is just the while loop
  4. import java.util.Scanner;
  5. public class PaintJob {
  6.  
  7.    
  8.         private static int SizeToCost = 115;
  9.         private static int PaintToCost = 1;
  10.         private static int LabourToCost = 8;     
  11.         private static int LabourCostPerHour = 18; 
  12.  
  13.  
  14.         public static void main(String[] args)
  15.         {       //previous code simplified + validation
  16.                 double RoomSize= getDoubleWithValidation("Enter size of each room (in squared feet): ");
  17.        
  18.                 double PaintCost = getDoubleWithValidation("Enter price of paint per gallon: ");
  19.        
  20.                 double RoomCount = getDoubleWithValidation("Enter number of rooms to paint: ");
  21.        
  22.        
  23.                 double RoomCostUnit = (RoomSize * RoomCount) / SizeToCost;
  24.  
  25.  
  26.                 double PaintCountTotal = PaintToCost * RoomCostUnit;
  27.  
  28.                 double LabourCountTotal = LabourToCost * RoomCostUnit;
  29.  
  30.  
  31.                 double PaintCostTotal = PaintCountTotal * PaintCost;
  32.  
  33.    
  34.                 double LabourCostTotal = LabourCountTotal * LabourCostPerHour;
  35.  
  36.        
  37.                 double JobCostTotal = PaintCostTotal + LabourCostTotal;
  38.        
  39.  
  40.                 double DisplayPaintCountTotal = (double)((int)(PaintCountTotal * 100) / 100.0);
  41.                 double DisplayLabourCountTotal = (double)((int)(LabourCountTotal * 100) / 100.0);
  42.                 double DisplayPaintCostTotal = (double)((int)(PaintCostTotal * 100) / 100.0);
  43.                 double DisplayLabourCostTotal = (double)((int)(LabourCostTotal * 100) / 100.0);
  44.                 double DisplayJobCostTotal = (double)((int)(JobCostTotal * 100) / 100.0);
  45.  
  46.                 String Message = "The number of gallons of paint required = " + DisplayPaintCountTotal + "\n" +
  47.                         "The hours of labor required = " + DisplayLabourCountTotal + "\n" +
  48.                         "The cost of the paint = " + DisplayPaintCostTotal + "\n" +
  49.                         "The labor charges = " + DisplayLabourCostTotal + "\n" +
  50.                         "The total cost of the paint job = " + DisplayJobCostTotal + "\n";
  51.        
  52.                 System.out.println(Message);
  53.         }
  54.         public static double getDoubleWithValidation(String msg) {
  55.              double temp = 0;
  56.             Scanner s = new Scanner(System.in);//make object of scanner
  57.        
  58.             System.out.println(msg);//prints msg
  59.             temp = s.nextDouble(); //gets the double
  60.            
  61.             while(temp<=0) { // validation
  62.                 System.out.println("Please, the number must be higher than 0");
  63.                 temp = s.nextDouble();
  64.             }
  65.             //s.close(); // dont close scanner object here
  66.             return temp;
  67.         }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment