Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java program that calculates the number of gallons of paint needed to pa

ID: 3746546 • Letter: W

Question

Write a Java program that calculates the number of gallons of paint needed to paint the walls of a rectangular room, and computes the price of paint to be purchased. The program prompts the user for the rectangular room dimensions (i.e. length, width, and height), and for the price per gallon of paint. The program should compute and display the wall area, the number of gallons of paint needed, the total price of paint to be purchased, and the percentage of wasted paint (i.e., not used). Assume that a gallon of paint covers about 250 square feet of wall space. Note: No fraction of a gallon of paint can be purchased.

Explanation / Answer

import java.util.Scanner; public class PaintCalculator { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter length of walls: "); double length = in.nextDouble(); System.out.print("Enter width of walls: "); double width = in.nextDouble(); System.out.print("Enter height of walls: "); double height = in.nextDouble(); System.out.print("Enter price of paint per gallon: "); double pricePerGallon = in.nextDouble(); double area = 2*(length*width + width*height + height*length); double gallonsOfPaintNeeded = area / 250.0; int cansPurchased = (int) Math.ceil(gallonsOfPaintNeeded); double price = pricePerGallon * cansPurchased; System.out.printf("Cost of painting the room is: $%.2f ", price); double wastedPercentge = 100*(cansPurchased - gallonsOfPaintNeeded) / gallonsOfPaintNeeded; System.out.println("Percentage of paint wasted is " + wastedPercentge + "%"); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote