do it by method which return the result(via parameter )to the main program which
ID: 3734476 • Letter: D
Question
do it by method which return the result(via parameter )to the main program which will print out the result
this program calculate the area of room's walls, and the final cost painting.*/
package calculatearea;
import java.text.DecimalFormat;
public class CalculateArea{
public static void main(String[] args) {
//set the constants
final int height= 10; //the height of the room on square feet unit
final int width= 15; // the width of the room on square feet unit
final int length = 20; //the length of the room on square feet unit
double totalarea;
final double costPerGallon= 43.50; //cost per Gallon
final int sqFeetPerGallon = 600;
double fainalCost;
double area1 = height * width; //calculate the area of two walls on the room
double area2 = height * length; //calculate another area of two walls on the room
DecimalFormat df2 = new DecimalFormat("#.##");
totalarea = 2 * (area1) + 2 * (area2);//calculate total of area
System.out.println(totalarea+" square feet"+" is a total of area");//output total of area
fainalCost = (totalarea / sqFeetPerGallon) * costPerGallon;
System.out.println("$ "+df2.format(fainalCost)+" is a fainal cost");//output the fainal cost painting
}
}
Explanation / Answer
Note: Plz Could u let me know if u need any changes.Thank You
_________________
CostOfPainting.java
public class CostOfPainting {
public static void main(String[] args) {
// set the constants
final int height = 10; // the height of the room on square feet unit
final int width = 15; // the width of the room on square feet unit
final int length = 20; // the length of the room on square feet unit
final double costPerGallon = 43.50; // cost per Gallon
final int sqFeetPerGallon = 600;
double finalCost;
finalCost = claCostOfPainting(length, width, height, sqFeetPerGallon,costPerGallon);
System.out.printf("$ %.2f is a final cost", finalCost);
}
private static double claCostOfPainting(int length, int width, int height,
int sqFeetPerGallon, double costPerGallon) {
double totalarea;
double area1 = height * width; // calculate the area of two walls on the
// room
double area2 = height * length; // calculate another area of two walls
// on the room
totalarea = 2 * (area1) + 2 * (area2);// calculate total of area
System.out.println(totalarea + " square feet" + " is a total of area");
return (totalarea / sqFeetPerGallon) * costPerGallon;
}
}
____________________
output:
700.0 square feet is a total of area
$ 50.75 is a final cost
______________Thank You
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.