Learning Objectives
After completion of this lab, you should be able to
Pay.javaAll labs in CS 110 will be done as pair programming teams. Your partner for today's lab is listed in the table below:
| Team 1 Aguilar Jr, Jaime Awan, Samara |
Team 2 Amezcua Gutierrez, Edson Barrett Wright, Matthew |
Team 3 Baird II, Owen Bloom, Thomas |
Team 4 Berman, Jake Cuddington, Christopher |
Team 5 Coudriet, Blake Field, Sarah |
| Team 6 Erickson, Joel Hansen, Mitchell |
Team 7 Goeke, Maxwell Hastings, Jake |
Team 8 Harris, Alexander Hogan, Martin |
Team 9 Heflick, Elizabeth Ling, Nathan |
Team 10 McCauley, Rylee Nash, Christopher |
| Team 11 Millard, Ryan Olivares, Scott |
Team 12 Olden, Gregory Shearer, Stetson |
Team 13 Quayle, Weston Wagster, Nathan |
Team 14 Straub-Walden, Andrew Smith, Stephanie |
Team 15 Williamson, Sarah Akana, Christopher |
| Fill in: Millard, Mikel | ||||
Note: Partners will change every week.
You may wish to review basic pair programming guidelines before you begin.
You should change roles every 10 to 15 minutes.
Chapter 1 of the textbook shows the code for calculating gross pay based on hourly pay rate and number of hours worked. While correct, it does not take into account getting paid at overtime rates when working more than 40 hours a week or deducting for taxes.
In this lab, you are given the beginning Java source code that calculates a user's gross pay taking into account overtime pay. This will give you practice reading and understanding Java code, even before actually learning the concepts
To help you practice debugging, there are a few errors in the code, both syntax errors and a logic error.
After debugging the program to correctly calculate gross pay, you will modify the program to deduct a flat 33% of gross pay for taxes.
Begin by developing test cases for this program. When developing test cases, it is a good idea to test boundary values. Assuming correct input for this program, there are four boundary values for testing purposes:
Using a calculator (Windows calculator works fine), calculate the gross pay, taxes, and net pay for the four test cases given below.
| Hours Worked | Hourly Pay Rate | Gross Pay | Taxes | Net Pay |
|---|---|---|---|---|
| 0 | $9.25 | |||
| 39 | $10.50 | |||
| 40 | $11.00 | |||
| 41 | $10.00 |
Write your calculated test case values in the Lab 2 assignment sheet. You will turn in this sheet at the end of lab for credit.
Pay.javaThe Java source code below is a simple program to calculate gross pay based on user's hours worked and hourly pay rate.
Note: it has been seeded with errors.
Pay.java and copy and paste the source code below into your program.With programming, there are may possible types of errors. Two general categories of errors we will examine in today's lab are syntax errors and logic errors
Syntax Errors are errors in the grammar of the programming language. Examples of syntax errors are spelling mistakes in variable names, missing semicolons, unpaired parenthesis or curly braces, etc.
Syntax Errors are caught by the compiler and listed out with line number and a description of the error found. As you will find, compilers are occasionally wrong in either the location or description of the error.
All syntax errors must be corrected before the program can be run. Once the program is able to run, this does not mean that it is correct, only that it contains no syntax errors.
Some experience is needed to interpret compiler error messages. Some are fairly straightforward, for example
Pay.java:29: ';' expected grossPay = (hoursWorked) * (1.5 * hourlyPayRate));^
means that in file Pay.java on line 29 a semicolon ';' was expected but instead it saw the character ')'
Some are a little bit harder to interpret. For example
Pay.java:18: cannot find symbol symbol : variablehours
means that in file Pay.java on line 18 the variable hours was used and the compiler was cannot find this symbol hours. Variable hours has not been declared as a variable in this program.
Pay.java program and find and correct the three syntax errors present in the program
Change pair partner roles. The driver should become the navigator, the navigator should become the driver.
Even though your program should now compile without errors and produce output, a logic error remains.
Logic Errors are errors in the logic of the algorithm. Examples of logic errors are statements out of order, errors in a formula, or missing steps.
Programs with logic errors can still run and give you output, but it may be the wrong output. Since jGRASP cannot generate a list of logic errors in your program, you may not realize you have errors unless you carefully check your output with your hand-calculated expected results.
grossPay = write out the formula
Change pair partner roles. The driver should become the navigator, the navigator should become the driver.
While the Pay program may now calculate gross pay correctly, in the real world, nothing can be said to be certain except death and taxes. Assume that the tax man takes a flat 33% of gross wages as taxes.
taxes = write out the formula netPay = write out the formula
Pay program to calculate and display taxes and net pay.
double values in Java, so 33% would be 0.33 in your programHow many hours did you work?15How much do you get paid per hour?10.00You earned $150.0 Taxes are $49.5 Your net pay is $100.5
Change pair partner roles. The driver should become the navigator, the navigator should become the driver.
In most cases, using literal values (like a tax rate of 0.33) inside of formulas are considered bad style.
0.330.33 in the calculations, replacing it with your named constant TAX_RATElab2 folder to the partner's USB thumb drive (or email it to them if they do not have a thumb drive).0.30 (30%), run your program and confirm your program's output is still correct
U:\labs\lab2 folder and turn in the Lab 2 assignment sheet at the start of Lab 3
You are allowed to drop one lab grade for the entire quarter. No late lab or program assignments are accepted.