Question: I need help doing a do-while loop in this code. It work fine but I need to add a do-while to prove the information please
I need help doing a do-while loop in this code.
It work fine but I need to add a do-while to prove the information please
package paint1;
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): ");
wallWidth = scnr.nextDouble();
// Calculate and output wall area
wallArea = wallHeight * wallWidth;
System.out.printf("Wall area: %.1f square feet", wallArea);
// Calculate and output the amount of paint (in gallons) needed to paint the wall
gallonsPaintNeeded = wallArea/squareFeetPerGallons;
System.out.println("Paint needed: " + gallonsPaintNeeded + " gallons");
scnr.close();
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
