Question
Due to my typo that was explained in the request but the code reflected the opposite. I am asking again. The code reflects the correct
Due to my typo that was explained in the request but the code reflected the opposite.
I am asking again. The code reflects the correct information but I am getting the error below. Overview
Many Java programs that you create will receive and process user input. In order to ensure that user input is accurate, you will need to use input validation and exception handling. For example, if you ask for a zip code, you want to ensure the user inputs a five-digit number. In this activity, you are given buggy code for a paint program. This program calculates the number of cans of paint required to paint a wall, given the walls height and width. You will first need to debug the existing code. Then you will improve it by adding code to validate user input and handle exceptions.
Prompt
For this assignment, you will complete the paint program by debugging the original code and adding code that validates user input and handles exceptions.
Before you begin, open the Virtual Lab by clicking on the link in the Virtual Lab Access module. Then open your IDE. Upload the Paint1.zip folder and review the code for the Paint1.java file. Use the Uploading Files to Eclipse Tutorial PDF to help you with this step.
First, you will debug the Paint1 class so that no errors remain and all calculations work correctly by completing the following:
Find and fix the three errors in the given code.
Use the following sample input values to test your program. If you have found and fixed all the errors, your output should exactly match the sample.
Next, you will add loops to validate all user input and handle exceptions so that code passes all test cases by completing the following:
Review the code, looking for the two code blocks where user input is required.
Implement a do-while loop in both blocks of code to ensure that input is valid and any exceptions are handled.
Use the two following sample sets of input to test your program. Since these inputs are invalid, your program should respond to each by prompting the user to enter valid input. This should continue to loop until valid input is received.
I'm a bit confused about this as it is giving me an error.
Error when looking at the console in Eclipse.
""Exception in thread ""main" java.lang.error: unresolved compilation problems:
InputMismatchException cannot be resolved to a type
at Paint1.main(Paint1.java:29)
at Paint1.main(Paint1.java:51)"
Below is the code. Not really sure what I am doing wrong?
import java.util.InputMismatchException; import java.util.Scanner; public class Paint1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); double wallHeight = 0.0; double wallWidth = 0.0; double wallArea = 0.0; double gallonsPaintNeeded = 0.0; final double squareFeetPerGallon = 350.0; // Get wall height from user input do { try { System.out.print("Enter wall height (feet): "); wallHeight = sc.nextDouble(); if (wallHeight2 errors, 0 warnings, 0 others Description Errors (2 items) Ex InputMismatchException cannot be resolved to a type InputMismatchException cannot be resolved to a type \begin{tabular}{|l|l|l|l|} \hline Resource & Path & Location & Type \\ \hline Paint1.java & /Paint1 & line 29 & Java Problem \\ \hline Paint1.java & /Paint1 & line 51 & Java Problem \\ \hline \end{tabular} Exception in thread "main" java.lang.Error: Unresolved compilation problems: InputMismatchexception cannot be resolved to a type InputMismatchexception cannot be resolved to a type at Paint1.main (Paintl.java: 29)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started