Question
This paint class needs to implement a do-while loop for valid input. A try and catch i would like to know how to implement into
This paint class needs to implement a do-while loop for valid input. A try and catch i would like to know how to implement into this class in addition.
import java.util.Scanner;
public class Paint1 {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
double wallHeight = 0.0;
double wallWidth = 0.0;
double wallArea = 0.0;
double gallonsPaintNeeded = 0.0;
final double squareFeetPerGallons = 350.0;
// Implement a do-while loop to ensure input is valid
// Prompt user to input wall's height
System.out.println("Enter wall height (feet): ");
wallHeight = scnr.nextDouble();
// Implement a do-while loop to ensure input is valid
// Prompt user to input wall's width
System.out.println("Enter wall width (feet): ");
wallHeight = scnr.nextDouble();
// Calculate and output wall area
wallArea = wallHeight * wallWidth;
System.out.println("Wall area:square feet");
// Calculate and output the amount of paint (in gallons) needed to paint the wall
gallonsPaintNeeded = wallArea/squareFeetPerGallons;
System.out.println("Paint needed: " + gallonsPaintNeeded + " gallons");
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started