CSI247: Lab 1: September 22, 2021
CSI247: Lab 1: September 22, 2021
• Create an class.
• Follow proper java project folder structure and compile from the command line.
Project Structure
Follow the steps below to create appropriate project structure for this lab.
• Create the directory structure for the package lab1.employee in the src directory.
You should end up with the structure in Figure 1, but without the Java files.
Lab 1 Classes
In this lab you are going to implement the class hierarchy given in Figure 2. All the three
classes should be in the lab1.employee package. Add the necessary package declaration
to the java classes.
1
Figure 1: The project directory structure for the lab. You can ignore the java files as
you will add them in the coming sections.
2
Employee Class
Create the class Employee in the package ”lab1.employee”. Add all the instance variables
and methods.
• Create a constructor that takes three parameters to initialise all the instance vari-
ables.
• The fullName() method should return a combination of the first and last names
separated by space.
• The print() method should use the printf() method to output the details of the
employee formatted as you want. Make sure you are also prining the earnings of
the employee too.
SalariedEmployee Class
A salaried employee has a fixed weekly salary. Their earnings are calculated monthly.
In this lab, you can assume that there are 4 weeks in a month.
• Create a constructor that takes the three parameters for the super class plus two
parameters for the class’ instance variables. In Java, we can call the constructor
from the super class using the keywork super(). The first line of the constructor
should call the super class constructor with the appropriate parameters.
HourlyEmployee Class
A hourly employee has a fixed hourly salary. The earnings are calculated monthly using
the hours worked weekly. In this lab, you can assume that there are 4 weeks in a month.
• Create a constructor that takes the three parameters for the super class plus one
parameter for the class’ instance variable. In Java, we can call the constructor
from the super class using the keywork super(). The first line of the constructor
should call the super class constructor with the appropriate parameters.
• Implement the getters and setters of the class. Note that there is no setter for
hourlyRate. This means that once it is set by the constructor, it can no longer be
changed.
• The earnings() method should return a monthly salary calculated using the hourly
rate, the hours and the number of weeks in a month.
3
Tester Class
• Create a class called LabTester in the lab1 package.
• Declare two more variables of type Employee. Create an object of type SalariedEm-
ployee and assign it to one of the varibale. Create another instance of type
HourlyEmployee and assign it to the remaining variable.
• You should now be able to compile the project using the command ”javac -d classes
-sourcepath src src/lab1/LabTester.java”
• Run the program using the command ”java -classpath classes lab1.LabTester”.