Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm struggling with figuring out the bug in this code it says that my first and last curly brace are wrong but they need to

I'm struggling with figuring out the bug in this code it says that my first and last curly brace are wrong but they need to be there?

import java.util.InputMismatchException; 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; //variable to exit the loop boolean endLoop = true; final double squareFeetPerGallons = 350.0; // Implement a do-while loop to ensure input is valid // Prompt user to input wall's height do { try { System.out.println("Enter wall height (feet): "); wallHeight = scnr.nextDouble(); System.out.println("Enter wall width (feet): "); wallWidth = scnr.nextDouble(); //make statements to correct invalid inputs if((wallHeight <= 0) && (wallWidth <= 0)) { throw new Exception(" Invalid height and width. Numbers must be greater than 0. "); } else if(wallHeight <= 0) { throw new Exception(" Invalid height. Height must be greater than 0. "); } else if(wallWidth <= 0) { throw new Exception(" Invalid width. Width must be greater than 0. "); } else { endLoop = false; } } //if not int or float catch(InputMismatchException excpt) { System.out.println(" Expected a number as input. "); scnr.nextLine(); } catch (Exception excpt) { System.out.println(excpt.getMessage()); scnr.nextLine(); } while(endLoop);

// Implement a do-while loop to ensure input is valid // Prompt user to input wall's width

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

}

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