Part 1: Get the Lab4.java file

In todays lab, you will be asked to debug code that has been written by someone else. This code will have both syntax errors and logic errors. To start off, download the Lab4.java file from the Blackboard and move it from the download directory to wherever you are most comfortable. If you are using Eclipse, create a new Java Project like you did for Labs 1, 2, and 3 and copy and paste the contents of the Lab4.java file into your new Lab4 project.

Once youve downloaded the file and are ready to start, try to compile and run this java file. Youll find that this file doesnt even compile correctly!

Part 2: Correct Syntax Errors

The reason that the Lab4 file doesnt compile correctly is that it has some syntax errors. These syntax errors prevent the compiler from properly reading and interpreting the Java code. Correct these errors and more on to the next section.

Part 3: Correct Logic Errors

In addition to the syntax errors you just corrected, the code has a number of logic errors. Logic errors dont prevent the code from compiling, but they do prevent the code from getting the correct answer when you run the program. If youve only corrected the syntax errors in the code and you try to run it, youll notice that selecting Option 1 at the menu actually performs the function that Option 2 should be handling. This is not the only logical error in the code. The Sample Output section this week has been expanded to cover all of the logical errors in the code, so use that as your guide as you correct the logical errors.

Please Note:

  • Please make sure to print something for every case.
  • Labs are not graded by a program, so you do not need to spend a large amount of time making the output match perfectly with the sample below. Do, however, make sure your output is reasonable. The goal here is for you to demonstrate that you understand the underlying concepts.

Sample Output:

User input is in blue.

Please select from the following options:
1) Calculate new balance after compound interest.
2) Calculate income tax.
1
Please enter your starting balance: 5000
Please enter your interest rate percentage: 2
Please enter the period (in years): 1
Your final balance is: $5100.0
----------
Please select from the following options:
1) Calculate new balance after compound interest.
2) Calculate income tax. 1
Please enter your starting balance: 5000
Please enter your interest rate percentage: 5
Please enter the period (in years): 1
Your final balance is: $5250.0
----------
Please select from the following options:
1) Calculate new balance after compound interest.
2) Calculate income tax.
1
Please enter your starting balance: 5000
Please enter your interest rate percentage: 5
Please enter the period (in years): 2
Your final balance is: $5512.5
----------
Please select from the following options:
1) Calculate new balance after compound interest.
2) Calculate income tax.
2
Please enter your income for 2015: 500
You owe $50.0 in taxes.
----------
Please select from the following options:
1) Calculate new balance after compound interest.
2) Calculate income tax.
2
Please enter your income for 2015: 9000
You owe $900.0 in taxes.
----------
Please select from the following options:
1) Calculate new balance after compound interest.
2) Calculate income tax.
2
Please enter your income for 2015: 25000
You owe $4750.0 in taxes.
----------
Please select from the following options:
1) Calculate new balance after compound interest.
2) Calculate income tax.
2
Please enter your income for 2015: 100000
You owe $26000.0 in taxes.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.