In this lab you will practice writing classes to model employees of a company who are paid in different ways. The employee data is stored in the file empdata.dat. The first line of the data file is the number of employee data in the remainder of the file. For each employee, the file indicates whether they are paid on an hourly or salaried basis and their name. For hourly-paid employees, the file lists the number of hours worked per week and the hourly pay rate. For salaried employees, the file lists the weekly salary.
Employee
that implements
the methods public String getName()
and
public double computeMonthlyPay()
. You may also
define a constructor for the class and necessary fields. For
this generic employee, the computeMonthlyPay()
method should just return 0.0
.
Employee
, named
HourlyEmployee
and
SalariedEmployee
. These classes should add
additional fields as necessary, contain appropriate
constructors to initialize those fields, and override the
computeMonthlyPay()
method to properly compute
the monthly pay.
EmployeeManager
class that reads in the data from
the data file (empdata.dat), and creates and initializes the
right kind of employee objects, storing them into an array
(Employee[]
). After reading in the data file, the
program should print out a table listing the employees' names
and their monthly pay rates, as follows:
Monthly Pay Rates Jane Doe $2151.79 John Hopkins $2200.00 Matt Thomas $1840.00 Angela Moneybags $3661.80 |
EmployeeManager
class, write a method,
public static String formatDollar(double val)
which converts a double value into a properly formatted string
for printing the value out as a dollar amount- that is, it
should ensure that there are always two digits after the
decimal point.
company
. That is, create a new folder and
move the Employee
,
SalariedEmployee
, and HourlyEmployee
files into that folder. At the top of each of those files now
you must include the statement package
company;
. In the EmployeeManager
file,
you will now need to import the company
package
in order to access the Employee classes. Try compiling and
running your program without having an import statement -- if
it does compile and run ok without an import statement,
then tell me, because something is wrong.
After you've finished these exercises, start looking at the next homework assignment, Homework 9.
You may work in pairs for this lab. Each pair should turn in one set of answers with both partners' names on it.
Upload your program files for this lab in the appropriate section of the Viking Web coursework for this class. Also hand in a printout of your program files.