Below is the modified code that assume that a gallon of paint covers about 350 square feet of wall space.
java
import java.util.Scanner;
public class PaintCalculator {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
double height;
double length;
double width;
double price;
// Prompts user for the dimensions of the room
System.out.print("Please enter the height of the room: ");
height = keyboard.nextDouble();
System.out.print("Please enter the length of the room: ");
length = keyboard.nextDouble();
System.out.print("Please enter the width of the room: ");
width = keyboard.nextDouble();
// Call WallAreaMethod to calculate wall area
double wallArea = WallAreaMethod(height, length, width);
// Call paintFormula to calculate paint quantity and price
price = paintFormula(wallArea, height, length, width);
// Display the final price
System.out.println("The total cost to paint the room is: $" + price);
keyboard.close();
}
// Calculates the area of the wall in a room
public static double WallAreaMethod(double height, double length, double width) {
double wallArea = 2 * height * (length + width);
return wallArea;
}
// Computes the quantity of paint needed and the price
public static double paintFormula(double wallArea, double height, double length, double width) {
double paintQuantity = wallArea / 350.0;
double price = paintQuantity * 32.0;
System.out.println("For a room of height " + height + " feet, length " + length + " feet, and width " + width
+ " feet you need to purchase " + paintQuantity + " gallons of paint.");
System.out.println("The price will be $" + price + ".");
return price;
}
}