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
- Created Three Methods in all; calculateWallArea(), calculatePaint(), and price()
- Method calculateWallArea() calculates area based on this formula Area=2*length*heigth+2*width*height+lenth*width
- 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
- Method price() calculates and dis[plays the price by calling method calculatePaint() that returns number of gallons. since one gallon is 32$