1713 Laboratory 10: The
DepartmentStore - Object
hierarchies and inheritance
Note: This is a two-week lab.
In the second week you will learn how to use the Javadoc documentation generator to produce professional-looking
documentation for your projects.
Use an abstract class.
Practice with the is-a relationship.
Use a helper class to handle I/O.
Use type-casting in a more complex program.
Use the instanceof operator to distinguish among subclasses.
Use protected class members to share information among classes
in the hierarchy.
Learn to use JavaDoc for program documentation.
Hand-in Requirements (Deliverables):
All projects and laboratories will be submitted electronically through webCT.
Zip up your entire project directory for submission.
(Right click on the project folder and follow the SentTo link.)
The project source directory should include the following classes:
DepartmentStore.java (final version) (5 pts)
DepartmentStoreTest.java (final version) (5 pts)
EmployeeIOTest.java (4 pts)
Employee.java (4 pts)
Javadoc documentation for the Employee class (2 pts)
You will be using the class hierarchy for StaffMember
shown in Figure 9.1 of the textbook
to implement a DepartmentStore class that will track the employees
of a particular store. The classes shown in Figure 9.3 (StaffMember),
Figure 9.5 (Employee), Figure 9.6
and Figure 9.7 (Hourly) are already written. Our department store doesn't
use volunteers, so the Volunteer class of Figure 9.4 isn't included. A helper
class EmployeeIO is also provided to create Employee
objects of various types by reading data from a file.
Part II explores the
use of this class. Part III makes the Employee class implement
Comparable. Part IV guides you through the development of a
class that uses Employee objects of various sorts. In Part V you will generate
Javadoc documentation for the classes in the project.
Part I: Setup:
Download and unzip the lab10setup
into a directory not under your eclipse workspace directory.
Make a lab10 project.
File -> Import -> General -> File System -> Next
Browse From directory and select the lab10 directory that you
unzipped. Click OK.
Below From directory, in the left pane, select the box for lab10.
Into folder should be lab10.
Only the last Options box, Create selected folders only, should be
You will be given two questions:
Overwrite .classpath: No
Pverwrite .project: No
In the eclipse Package Explorer, open up lab10.
You should see three items listed including src and employees.txt.
Open src and deparmentstorepkg. There should be 8 java files.
Part II: Using the EmployeeIO class.
In EmployeeIOTest change the printed line to contain your name.
Compile and run.
Instantiate a EmployeeIO object called
empIn in EmployeeIOTest.
employees.txt as the file name parameter. When you instantiate
the EmployeeIO object, it opens the specified file for input.
Compile and run EmployeeIOTest again. If you get a red line of
text saying Didn't open ... check the spelling of the parameter
of your EmployeeIO constructor.
The EmployeeIO class has a method called
returns a new object that is-aEmployee
(e.g., Employee, Hourly, or Executive) based
on the next entry read from the file.
If all of the entries have already been read, or there is an error
of some kind,
next throws a NoSuchElementException.
class also has a hasNext method that returns true if
there is another StaffMember in the file.
Add a loop to EmployeeIOTest
to read in the objects from
employees.txt and output them. Note:NoSuchElementException is an example of a
RuntimeException. The compiler does not force you to catch these,
as they are unexpected errors.
(On your own) Add code to store the employees in an ArrayList called empList.
After reading is complete,
output the elements of empList.
Part III: Making Employee implement Comparable
(On your own) Add code to make Employee implement Comparable. You should
use the employee's name to determine order. Break ties with the social security number.
(On your own) Print the list of employees in name order.
You can create an array of Comparable from the ArrayListempList by calling:
Comparable  empArray = new Comparable ;
empArray = (Comparable)(empList.toArray(empArray));
You can sort an array of Comparable with one of the sorting methods
from Sort in arrayutilitypkg
or you can just use Arrays.sort:
Part IV: The DepartmentStore class
The DepartmentStore class keeps track of all the information about
the employees for a particular store.
The DepartmentStore has a name and methods to add, remove,
and find particular employees.
The DepartmentStore has the usual accessor
and toString methods as well as various forms of printing as
Internally, use an ArrayList to hold the employees.
In DeparmentStoreTest, change the name printed to your name,
compile and run.
Add client code to DepartmentStoreTest to instantiate a
DepartmentStore object called store,
representing the Allied Services Department Store.
Implement a toString method for DepartmentStore.
Write an addEmployee(Employee emp) method that adds the specified employee to the store's rosters.
Test this method by adding the employees of employees.txt
(On your own) Write the following print methods of
and add client code in DepartmentStoreTest to test them:
print - prints the information about every employee. Include their
classification in the printout.
printEmployees - prints all the information about each employee
who is an employee, but not an executive or hourly. (You will need to use
the instanceof operator here.)
printExecutives - prints all the information about each executive
employee. (You will need to use the instanceof operator here.)
printHourly prints all the information about each hourly employee.
(You will need to use the instanceof operator here.)
Write a findEmployee(String ssn) method in DepartmentStore
that returns an Employee object corresponding to the specified
null if the employee is not found. Add client code
to DepartmentStoreTest to test this method.
(On your own) Write and test
removeEmployee(String ssn) and removeEmployee(Employee emp)
(On your own)
Write an updateHours(String ssn, int hours) method in DepartmentStore
that adds the specified hours to the specified hourly employee. If the
employee is not an
Hourly return false, otherwise return true. Use
findEmployee. Add client code to DepartmentStoreTest
to test this.
(On your own)
Modify Executive so that the toString also displays the
current value of bonus. See the toString of Hourly
for a prototype.
Write a method awardBonus(double amount) that sets the bonus for
each executive to amount. Add client code to DepartmentStoreTest
to test this method.
Part IV: Javadoc
Javadoc is Java's automatic documentation facility.
It produces documentation similar to the documentation for Java itself.
(See Appendix I of the textbook for more details on Javadoc.)
In this part of the lab you will generate the Javadoc documentation for the
Provide header documentation for the class and for each constructor.
Also document all non-private attributes and methods.
(There should not be any non-prive atributes for this class.
To guide you, the EmployeeIO and the StaffMember
classes have already been documented.)
Create a general comment for the class and for each public method.
For each public method include @param and @return tags
Once you have inserted the appropriate comments in your code, you must generate
the javadoc files from the source code.
To do this in eclipse, go to
Project -> Generate Javadoc ...
If the Javadoc command field is not filled in, click Condifure...
and locate the javadoc.exe command. It is probably in a bin
directory under C:\Program Files\Java. Look for a directory
that starts with jdk.
In the left hand pane, select the directory containing your source code, lab10 -> src -> departmentstorepkg
Under Create Javadoc for members with visibility select Public
and make sure Use Standard Docet is selected. The destination should
end in lab10\doc.
Click Finish to build the files.
To see the results, point your browser to lab10\doc\index.html
and select the Employee class under Class Summary.