Skip to content
Advertisement

Issue with addressing variables from different method

I am just learning to code in Java and ran into a problem. The task description was following: “The class SalaryCountingWithMethods below asks for three floating point numbers (work hours, salary per hour and tax percent) and then counts the salary before and after taxes as well as the tax part of the salary based on the information given to the program.” I have been stuck on the problem for days now and i just cannot find a solution. This is my progress so far:

JavaScript

and i am getting the following error:

JavaScript

Advertisement

Answer

The class SalaryCountingWithMethods below asks for three floating point numbers
The issue might be you are dealing with floating-point numbers but the methods you are defining are accepting integer input. This will cause java.util.InputMismatchException error when you give double instead of integer.

JavaScript

You should accept double as input not integer.

JavaScript

You should do the same for other two methods askSalaryPerHour() and askTaxPercent().

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement