CS16 -- E X A M #1

Start with a working payroll program that does the following:
  • For each employee
    • Read input (including hours, rate, etc.) for each employee
    • Calulate gross-pay, etc. for that employee
    • Output paystub and paycheck for that employee
  • Also output a summary report, after the last employee.
Copy your (working) payroll program to a file named "XYZexam1.java" (where "XYZ" are YOUR initals). Use that file as the basis for this exam, modify it as described below, and upload it into your folder on the website at http://suffolk.li/cs16/81cs16/students/

NOTE: Exam grade is based on your added code only, and will NOT be affected by any incompleteness of your "payroll" program.   However, declarations must be correct for all variables used by Java code you add for this exam, and your program must compile properly and execute added features correctly.   Also see "CODING STANDARDS".


Below are the added features (for this exam).


  1. Validate the input for the "overtime-code" input, to make sure the user inputs only a 1, 2, 3, 4, or 5.
    Enforce this restriction with a new method named askcode() that is called instead of the common method for integer input aski(). After prompting for the input (using the string passed to it as an argument), your askcode() method should check the value:   If the value violates a restriction, output a message and prompt again for input; return the input value if and only if it meets all restrictions,.

  2. Check the weekly hours input, using new method named askhours() to enforce the following restrictions:
    1. Reject negative values.
    2. Reject values greater than 168 (24*7).
    3. Require hours to be rounded to the nearest tenth of an hour.
    If an input value is too big or too small, output an error message, and prompt again for user input. If the value has not been rounded off to the nearest tenth, then correct this value silently, and accept it.

  3. Add code 3 to the grosspay calculations
    In your method for computing gross-pay, add a new treatment for employess where the "code" is 3: NOTE: It is a good idea to use a final constant name instead of constant values, such as "40". Since this is the same value used for overtime calculations, it is probably a good idea to "hoist" this constant to global scope.

  4. If the employee ID number is divisible by 7 (seven), with no remainder, then give that employee a $10 bonus this week and add a message to the paystub saying "Lucky Seven -- $10 bonus".

  5. Add the following new items to the summary report.   (NOTE: This modifies both output and calculations.)