Assume that a gallon of paint covers about 350 square feet of wall space. Create anapplication with a main() method that prompts the user for the length, width, andheight of a rectangular room. Pass these three values to a method that does the following:-a. Calculates the wall area of a roomb. Passes the calculated wall area to another method that calculates and returns thenumber of gallons of paint needed.c. Displays the number of gallons needed.d. Computes the price based on a paint price of $32 per gallon, assuming that the paintercan buy any fraction of a gallon of paint at the same price as a whole gallon.e. 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 cielings is $64 dollars. Save as PaintClculator.java

**Note: I can prompt the user, but I can't get a return from my code.
import java.util.Scanner;
public class PaintCalculator {
public static void main(String [] args)
{
Scanner keyboard = new Scanner(System.in);

double wallArea;
double height;
double length;
double width;
double price;
double WallArea;
double paintQuantity;
//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();

WallAreaMethod(height, length, width);
}

//Calulates the area of the wall in a room
public static double WallAreaMethod(double height, double length, double width)
{
double wallArea;
wallArea = length * height * width * height;

return wallArea;
}
//Computes the quanity of paint needed
public static double paintFormula(double wallAreaMethod, double price, double height, double length,double width)
{

double wallArea;
double paintQuantity;

paintQuantity = wallAreaMethod * 2 / 350;


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 + ".");
price = paintQuantity * 32.0;
return price;
}

}

Respuesta :

ijeggs

Answer:

import java.util.Scanner;

public class PaintClculator {

   public static void main(String[] args) {

Scanner in = new Scanner(System.in);

       System.out.println("Enter Values for length, width, and height of the room");

       double length = in.nextDouble();

       double width = in.nextDouble();

       double height = in.nextDouble();

       double wallArea = calculateWallArea(length,width,height);

       double noGallons = calculatePaint(wallArea);

       double price = price(noGallons);

       System.out.println("Price is: "+ price);

   }

   // Creating Method to Calculate Wall Area

   public static double calculateWallArea( double length, double width, double height){

       // formular for the surface area of a room Area=2*length*heigth+2*width*height+lenth*width

       double Area = 2*length*height+2*width*height+length*width;

       System.out.println("Wall Area: "+Area);

       return Area;

   }

   //Creating method to calculate amount of paint

   public static double calculatePaint(double Area){

       double noGallons = Area/350;

       System.out.println("Number of gallons: "+noGallons);

       return noGallons;

   }

   // Creating Method Calculate Price

   public static double price(double noGallons){

       return noGallons*32;

   }

}

Explanation

  1. Created Three Methods in all; calculateWallArea(), calculatePaint(), and price()
  2. Method calculateWallArea() calculates area based on this formula Area=2*length*heigth+2*width*height+lenth*width
  3. The value of Area is passed to method calculatePaint() Which calculates the number of gallons required to cover the area given that one gallon covers 350 wall space
  4. Method price() calculates and dis[plays the price by calling method calculatePaint() that returns number of gallons. since one gallon is 32$
ACCESS MORE