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!
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.
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.
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.