I\'m stuck on this computer science program can someone help me please, thanks i
ID: 3667376 • Letter: I
Question
I'm stuck on this computer science program can someone help me please, thanks in advance
Explanation / Answer
import java.util.Scanner;
import java.text.DecimalFormat;
/**
* @author Srinivas Palli
*
*/
public class PaintJobEstimator {
/**
* @param args
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
try {
int numberOfRooms;
double pricePerGallon;
System.out.print("Enter the number of rooms: ");
numberOfRooms = input.nextInt();
System.out.print("Enter the price of paint per gallon: ");
pricePerGallon = input.nextDouble();
int roomCount = 1;
double totalWallSpace = 0;
while (roomCount <= numberOfRooms) {
System.out.println("Room No: " + roomCount);
System.out.print("Enter wall Space: ");
double wallSpaceForRoom = input.nextInt();
roomCount += 1;
totalWallSpace += wallSpaceForRoom;
}
double paintGallonsRequired = gallonsOfPaint(totalWallSpace);
double laborHoursRequired = hoursOfLaborRequired(totalWallSpace);
double laborCost = laborCharges(laborHoursRequired);
double paintCost = costOfPaint(paintGallonsRequired, pricePerGallon);
totalCostOfPaintJob(laborCost, paintCost, totalWallSpace);
} catch (Exception e) {
// TODO: handle exception
}
}
/**
* @param wallSpace
* @return
*/
public static double gallonsOfPaint(double wallSpace) {
double paintGallons = wallSpace / 115;
return paintGallons;
}
/**
* @param wallSpace
* @return
*/
public static double hoursOfLaborRequired(double wallSpace) {
double laborHours = (wallSpace / 115) * 8;
return laborHours;
}
/**
* @param gallons
* @param price
* @return
*/
public static double costOfPaint(double gallons, double price) {
double paintCost = gallons * price;
return paintCost;
}
/**
* @param hours
* @return
*/
public static double laborCharges(double hours) {
double totalLaborCharges = hours * 18;
return totalLaborCharges;
}
/**
* @param laborCost
* @param paintCost
* @param totalWallSpace
*/
public static void totalCostOfPaintJob(double laborCost, double paintCost,
double totalWallSpace) {
DecimalFormat twoDecimal = new DecimalFormat("#,##0.00");
double totalCost = laborCost + paintCost;
System.out.println("Total Wall Space: " + totalWallSpace);
System.out.println("Labor cost: $" + twoDecimal.format(laborCost));
System.out.println("Paint cost: $" + twoDecimal.format(paintCost));
System.out.println("The totalcost of the paint job is: $"
+ twoDecimal.format(totalCost));
}
}
OUTPUT:
Enter the number of rooms: 2
Enter the price of paint per gallon: 1054
Room No: 1
Enter wall Space: 580
Room No: 2
Enter wall Space: 460
Total Wall Space: 1040.0
Labor cost: $1,302.26
Paint cost: $9,531.83
The totalcost of the paint job is: $10,834.09