I have been working on this for hours and I just can't make sense of how to implement a try-catch in these two do while loops to catch if user enters a non-int. I know there are posts on this, but I can't seem to get it. I greatly appreciate any advice.
public class Paint {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
double wallHeight;
double wallWidth;
double wallArea = 0.0;
double gallonsPaintNeeded = 0.0;
final double squareFeetPerGallons = 350.0;
// Implement a do-while loop to ensure input is valid
// Handle exceptions(could use try-catch block)
do {
System.out.println("Enter wall height (feet): ");
wallHeight = scnr.nextDouble();
} while (!(wallHeight > 0));
// Implement a do-while loop to ensure input is valid
// Handle exceptions(could use try-catch block)
do {
System.out.println("Enter wall width (feet): ");
wallWidth = scnr.nextDouble();
} while (!(wallWidth > 0));
// Calculate and output wall area
wallArea = wallHeight * wallWidth;
System.out.println("Wall area: " + wallArea + " 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");
}
}