CSci 161 C
Third exercise set
Due:
- Part I will be due in class Wednesday, October 4
- Part II will be due in class Thursday, October 19 (Please note change
in due-date)
Part I (20 pts.):
Implement the Employee class as described on Exam #1, including (a new field)
an employee number (a String). Include
- Both constructors given on the exam. The first constructor should
accept both employee number and employee name, the second constructor should
accept all fields.
- Accessors for all fields
- Accessor for the gross pay (exam problem). Please note that there
are two ways of doing this: We could devise a new field called (say)
grossPay and set the accessor for grossPay to modify the field, and have the
accessor for grossPay then return the (modified) value of the field.
The second method (which I would like for this exercise) is not to have a
grossPay field, but to simply calculate and return the grossPay through a
method call. Notice that the user should not be able to tell the
difference between one approach and the other. With this
implementation, we might say that grossPay is a virtual field.
- Modifiers for hoursWorked and rateOfPay.
- Over-ride the toString method to return the employee information in some
fashion.
Turn in: Source listing for the class and the class
documentation. To get to the class documentation, select Tools -> Project
Documentation from the BlueJ project window (cntrl-J is a shortcut). Be
sure to test out all of your methods!
Part II (20 pts.):
Create a WorkingGroup class which contains an ArrayList of Employee objects.
Include the following two methods:
- A constructor which, when called, will use console input/output to first
ask the user for the number of employees in the group and which will then,
for each employee
- As the user for the employee's number, name, rate of pay, and hours
worked.
- Create a new employee object and put it in the ArrayList. Please
note that you should do this using anonymous object creation (see pages 102
- 103 of the textbook.
- A report method which uses an iterator to go through the list of all
employees (remembering that there may be more than three eventually) and
which prints a report with each employee's number, name, rate of pay, hours
worked, and gross pay. At the end of the report should be printed the
total number of employees, the total hours worked, and the total gross pay.
- A search method which accepts as an argument an employee number (a
string) and which returns the employee name (if found in the ArrayList) and
the string "error" of the employee number is not found (iterate through the
array list until the entry is found or the array list has been completely
processed).
Test your program with the following data:
- E01, MARPLE,
15.0, 4
- E02, POIROT, 12.0, 50
- E03, HOLMES, 25,
30
Turn in: Source listing for the class and the class
documentation together with a copy of the report. To print
the report
- Go to the options menu item on the terminal page.
- Select "save to file"
- Save the output to a file (.txt might work out best)
- Use notepad or some other program to open the file just created and
print it.