View the step-by-step solution to:


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(;

    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");



Top Answer

import java.util.Scanner; import java.util.InputMismatchException; public class Paint1 { public static void main ( String[]... View the full answer

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question