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

JAVA already started it-having trouble on the 2nd part (1) Prompt the user to in

ID: 2247623 • Letter: J

Question

JAVA

already started it-having trouble on the 2nd part

(1) Prompt the user to input a wall's height and width. Calculate and output the wall's area. (3 pts)

(2) Extend the program from part 1 to also calculate and output the amount of paint in gallons needed to paint the wall. Assume a gallon of paint covers 350 square feet. Store this value using a const double variable. (3 pts)

CODE:

import java.util.Scanner;

class Wall{
//instance variables
private double height;
private double width;

Scanner scnr = new Scanner(System.in);

final double SQUARE_FEET_PER_GALLON = 350.0; //constant variable to hold feet/galloon for painting wall

public Wall(){
inputHeight();
inputWidth();
}

public void inputHeight(){
System.out.println("Enter the height of wall(feet):");
height = scnr.nextDouble();
}
  


// FIXME (1): Prompt user to input wall's width
public void inputWidth(){
System.out.println("Enter the width of wall(feet):");
width = scnr.nextDouble();
}

//Accessor method ("getter") for the private height variable
public double getHeight(){
return height;
}

//Accessor method ("getter") for the private height variable
public double getWidth(){
return width;
}

// FIXME (1): Calculate the wall's area, using the wall's height and width instance variables
public double calculateArea(){
return height*width;
}

// FIXME (2): Calculate the amount of paint in gallons needed to paint the wall
public double getNumberOfPaintGallons(){
double wallArea = calculateArea();


}
}

public class PaintEstimator {
public static void main(String[] args) {
/* NOTE: IN BlueJ, we could run the program by right-clicking to make a wall object, and then calling the
methods in order. Here, in the main method we are calling the methods and printing the answers in a user-friendly way
*/
Wall myWall= new Wall(); //make a wall object, which will prompt the user to input height & width of wall.
  
double wallArea = 0.0; //local method variable to hold the area for printing
// Calculate and output wall area
wallArea = myWall.calculateArea(); // FIXME (1): Calculate the wall's area (in Wall class)
System.out.println("Area of the wall: " ); // FIXME (1): Finish the output statement so the variable prints
  
  
// FIXME (2): Calculate and output the amount of paint in gallons needed to paint the wall
System.out.println("Paint needed: " + + "gallons");
  
return;
}
}

Explanation / Answer

Wall.java


import java.util.Scanner;
class Wall {
//instance variables
private double height;
private double width;

Scanner scnr = new Scanner(System.in);

final double SQUARE_FEET_PER_GALLON = 350.0; //constant variable to hold feet/galloon for painting wall

public Wall() {
inputHeight();
inputWidth();
}

public void inputHeight() {
System.out.println("Enter the height of wall(feet):");
height = scnr.nextDouble();
}


// FIXME (1): Prompt user to input wall's width
public void inputWidth() {
System.out.println("Enter the width of wall(feet):");
width = scnr.nextDouble();
}

//Accessor method ("getter") for the private height variable
public double getHeight() {
return height;
}

//Accessor method ("getter") for the private height variable
public double getWidth() {
return width;
}

// FIXME (1): Calculate the wall's area, using the wall's height and width instance variables
public double calculateArea() {
return height * width;
}

// FIXME (2): Calculate the amount of paint in gallons needed to paint the wall
public double getNumberOfPaintGallons() {
double wallArea = calculateArea();
return wallArea / SQUARE_FEET_PER_GALLON;
}
}

_________________

PaintEstimator.java

public class PaintEstimator {

public static void main(String[] args) {
/* NOTE: IN BlueJ, we could run the program by right-clicking to make a wall object, and then calling the
methods in order. Here, in the main method we are calling the methods and printing the answers in a user-friendly way
*/
Wall myWall = new Wall(); //make a wall object, which will prompt the user to input height & width of wall.

double wallArea = 0.0; //local method variable to hold the area for printing
// Calculate and output wall area
wallArea = myWall.calculateArea(); // FIXME (1): Calculate the wall's area (in Wall class)
System.out.println("Area of the wall: " + wallArea); // FIXME (1): Finish the output statement so the variable prints

double gallons = myWall.getNumberOfPaintGallons();
// FIXME (2): Calculate and output the amount of paint in gallons needed to paint the wall
System.out.println("Paint needed: " + gallons + " gallons");

return;

}

}

____________________

Output:

Enter the height of wall(feet):
15
Enter the width of wall(feet):
12
Area of the wall: 180.0
Paint needed: 0.5142857142857142 gallons

_____________Could you rate me well.Plz .Thank You