Need assitance with this problem. I have provided the problem statement with its
ID: 3908527 • Letter: N
Question
Need assitance with this problem. I have provided the problem statement with its answer template and my coding. I have also provided the error message that keeps popping up when i run the program.
(1) Prompt the user to input a wall's height and width. Calculate and output the walls area. (2 pts) Note: This zyLab outputs a newline after each user-input prompt. For convenience in the examples below, the user's input value is shown on the next line, but such values don't actually appear as output when the program runs Enter wall height (feet): 12.0 Enter wall width (feet): 15.0 Wall area: 180.0 square feet (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. (2 pts) Enter wall height (feet): 12.0 Enter wall width (feet): 15.0 Wall Paint needed: 0.5142857142857142 gallons area: 180.0 square feet (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. (2 pts) Enter wall height (feet): 12.0 Enter wall width (feet): 15.0 Wall area: 180.0 square feetExplanation / Answer
import java.awt.*; import java.util.Scanner; import java.lang.Math; // Note: Needed for math functions in part (3) public class PaintEstimator { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); double wallHeight = 0.0; double wallWidth = 0.0; double wallArea = 0.0; System.out.print("Enter wall height (feet): "); wallHeight = scnr.nextInt(); //System.out.println(Math.floor(wallHeight)); System.out.print("Enter wall width (feet): "); wallWidth = scnr.nextInt(); //System.out.println(Math.floor(wallWidth)); // FIXME (1): Prompt user to input wall's width // Calculate and output wall area wallArea = 0.0; wallArea = wallHeight * wallWidth; // FIXME (1): Calculate the wall's area System.out.printf("Wall area: %.0f square feet ", wallArea); // FIXME (1): Finish the output statement final double perGallonArea = 350; double paintRequired = wallArea/perGallonArea; System.out.println("Paint needed: " + paintRequired + " gallons"); // FIXME (2): Calculate and output the amount of paint in gallons needed to paint the wall // FIXME (3): Calculate and output the number of 1 gallon cans needed to paint the wall, rounded up to nearest integer int cansNeeded = (int) Math.ceil(paintRequired); System.out.println("Cans needed: " + cansNeeded + " can(s)"); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.