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

1. Assume that a gallon of paint covers about 350 square feet of wall space. Cre

ID: 3746407 • 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

import java.util.Scanner;

import java.lang.Math;

public class PaintCalculator{

public static void main(String []args){

Scanner obj = new Scanner(System.in);

System.out.println("Enter length, width and height of room respectively:");

int length = obj.nextInt();

int width = obj.nextInt();

int height = obj.nextInt();

  

int area = computeArea(length, width, height);

double money = paintNeeded(area);

System.out.println("Money needed is $" + money);

}

public static int computeArea(int len, int wid, int ht){

int area = 2 * len * ht + 2 * wid * ht;

return area;

}

public static double paintNeeded(int area){

double paintReq = area / 350;

System.out.println(paintReq + " gallons of paint is needed");

double moneyReq = Math.ceil(paintReq) * 32;

return moneyReq;

}

}