1. Assume that a gallon of paint covers about 350 square feet of wall space. Cre
ID: 3746754 • Letter: 1
Question
1. Assume that a gallon of paint covers about 350 square feet of wall space. Create an application with a main() method that prompts the user for the length, width, and height of a rectangular room. Pass these three values to a method that does the following:
- Calculates the wall area for a room
- Passes the calculated wall area to another method that calculates and returns the number of gallons of paint needed
- Displays the number of gallons needed
- Computes the price based on a paint price of $32 per gallon, assuming that the painter can buy any fraction of a gallon of paint at the same price as a whole gallon
- Returns the price to the main() method
The main() method displays the final price. For example, the cost to paint a 15- by-20-foot room with 10-foot ceilings is $64. Save the application as PaintCalculator.java.
Explanation / Answer
If you have any doubts, please give me comment...
import java.util.Scanner;
public class PaintCalculator{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double length, width, height;
System.out.print("Enter length: ");
length = in.nextDouble();
System.out.print("Enter width: ");
width = in.nextDouble();
System.out.print("Enter height: ");
height = in.nextDouble();
double area = calculateArea(length, width, height);
System.out.println("Area of Room: "+area);
double no_of_gallons = Math.ceil(gallonsNeed(area));
System.out.println("You will need "+no_of_gallons+" gallons");
System.out.println("The price to paint the room is $"+(no_of_gallons*32));
}
public static double calculateArea(double length, double width, double height){
return 2*height*(length+width);
}
public static double gallonsNeed(double area){
return area/350;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.