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

I need help compiling this Java code.. The code works but I need the code to out

ID: 3913238 • Letter: I

Question

I need help compiling this Java code.. The code works but I need the code to output the Paint Needed (0.5142857142857142) and Cans Needed (1 can(s))
thanks!


import java.util.Scanner; // Needed for user input
import java.lang.Math; // Needed for math functions

/**
* @author Marlene Azevedo
*/
public class PaintEstimator {
public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);
double wallHeight = 0.0; //12ft
double wallWidth = 0.0; //15ft
double wallArea = 0.0; //180.0 square feet
double gallonsPaintNeeded = 0.0; //0.5142857142857142 gallons
int cansNeeded = 0; //1 can(s)
  
final double squareFeetPerGallons = 350.0; //h*w = sqrt footage => 12x15=180.0 sqrt footage
final double gallonsPerCan = 1.0;
  
System.out.println("Enter wall height (feet): "); //12ft
wallHeight = scnr.nextDouble();
  
// Prompt user to input wall's width
System.out.println("Enter wall width (feet): "); //12ft
wallWidth = scnr.nextDouble();
  
// Calculate and output wall area
wallArea = wallHeight * wallWidth; // Math 180.0 = 12 x 15 area = height * width
System.out.println("Wall area: " + wallArea + " square feet"); // outputs wall area
wallArea = scnr.nextDouble();
  


//code stops here unless 350.0 is inserted manually
gallonsPaintNeeded = wallArea / squareFeetPerGallons; // Math 180.0 / 350.0 = 0.5142857142857142 gallons
  
System.out.println("Paint needed: " + gallonsPaintNeeded + " gallons"); // should output gallonsPaintNeeded
gallonsPaintNeeded = scnr.nextInt();
      
cansNeeded = (int)((gallonsPaintNeeded / gallonsPerCan) +1); //had to fix this part by adding (int) and (+1)
System.out.println("Cans needed: " + cansNeeded + " can(s)"); // Needs to print out cansNeeded
cansNeeded = scnr.nextInt();

return;
}
}

zyBooks My library IT 145 home 2.20: Debugging:Painting a wall (Java) ?zyBooks catalog Help/FAQ ? Marlene A (2) Extend 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. (Submit for 1 points, so 3 points total). Enter wall height (feet) 12 Enter wall width (feet): 15 Wall area: 180.0 square feet Paint needed: 0.5142857142857142 gallons (3) Extend to also calculate and output the number of 1 gallon cans needed to paint the wall. Hint: Use a math function to round up to the nearest gallon. (Submit for 2 points, so 5 points total). Enter wall height (feet) 12 Enter wall width (feet): 15 Wall area: 180.0 square feet Paint needed: 0.5142857142857142 gallons Cans needed: 1 can (s) LAB ACTIVITY 2.20.1: Debugging Painting a wall (Java) 0/5

Explanation / Answer

Most of your code is correct. I have same two simple modifications to the code so that it outputs the required number of cans and the volume of paint. After you have asked the user to input the wallHeigth and wallWidth you don't need to ask for anything else, as area and paint needed can be calculated by your code. Hence I have removed the lines wallArea =scnr.nextDouble(); and cansNeeded =scnr.nextDouble() and made some formatting changes. Here is the modified code:

import java.util.Scanner; // Needed for user input

import java.lang.Math; // Needed for math functions

/**

* @author Marlene Azevedo

*/

public class PaintEstimator {

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

double wallHeight = 0.0; //12ft

double wallWidth = 0.0; //15ft

double wallArea = 0.0; //180.0 square feet

double gallonsPaintNeeded = 0.0; //0.5142857142857142 gallons

int cansNeeded = 0; //1 can(s)

final double squareFeetPerGallons = 350.0; //h*w = sqrt footage => 12x15=180.0 sqrt footage

final double gallonsPerCan = 1.0;

System.out.print("Enter wall height (feet): "); //12ft

wallHeight = scnr.nextDouble();

// Prompt user to input wall's width

System.out.print(" Enter wall width (feet): "); //12ft

wallWidth = scnr.nextDouble();

// Calculate and output wall area

wallArea = wallHeight * wallWidth; // Math 180.0 = 12 x 15 area = height * width

System.out.print(" Wall area: " + wallArea + " square feet"); // outputs wall area

//code stops here unless 350.0 is inserted manually

gallonsPaintNeeded = wallArea / squareFeetPerGallons; // Math 180.0 / 350.0 = 0.5142857142857142 gallons

System.out.println(" Paint needed: " + gallonsPaintNeeded + " gallons"); // should output gallonsPaintNeeded

cansNeeded = (int)((gallonsPaintNeeded / gallonsPerCan) +1); //had to fix this part by adding (int) and (+1)

System.out.println("Cans needed: " + cansNeeded + " can(s)"); // Needs to print out cansNeeded

return;

}

}


Sample Output :-

~/chegg ??? javac PaintEstimator.java 13:57:09

~/chegg ??? java PaintEstimator

Enter wall height (feet): 12

Enter wall width (feet): 15

Wall area: 180.0 square feet

Paint needed: 0.5142857142857142 gallons

Cans needed: 1 can(s)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote