Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions