1. Engineering
  2. Computer Science
  3. no late assignment will be accepted make sure that you...

Question: no late assignment will be accepted make sure that you...

Question details

No late assignment will be accepted.

Make sure that you write every line of your code.

Using code written by someone else will be considered a violation of the academic integrity and will result in a report to the Dean's office.

Minimal Submitted Files

You are required, but not limited, to turn in the following source files:

Assignment5.java (Download this file and use it as your driver program for this assignment. You need to add more code to complete it.)
Employee.java
FullTimeEmployee.java
PartTimeEmployee.java
EmployeeParser.java

Requirements to get full credits in Documentation

  1. The assignment number, your name, StudentID, Lecture number/time, and a class description need to be included at the top of each class/file.
  2. A description of each method is also needed.
  3. Some additional comments inside of methods (especially for a "main" method) to explain code that are hard to follow should be written.

You can look at Java programs in the text book to see how comments are added to programs.

Skills to be Applied

In addition to what has been covered in previous assignments, the use of the following items, discussed in class, will probably be needed:

Inheritance
The protected modifier
The super Reference     
Abstract class
NumberFormat/DecimalFormat
ArrayList

Program Description

Class Diagram:

hw5ClassDiagram.jpg

In Assignment #5, you will need to make use of inheritance by creating a class hierarchy for bank accounts.

Employee class

Employee is an abstract class, which represents the basic attributes of any employee. It is used as the root of the employee hierarchy. It has the following attributes (should be protected):

Attribute name

Attribute type

Description

firstName

String

The first name of an employee

lastName

String

The last name of an employee

employeeId

String

The id of an employee

payAmount

double

The pay amount of an employee

The following constructor method should be provided to initialize the instance variables. Please refer to the UML class diagram for their parameter types, and return type.

public Employee(String firstname, String lastname, String id)

The instance variables firstName, lastName, employeeId are initialized to the value of the first parameter, the second parameter, and the third parameter respectively, and payAmount should be initialized to 0.0.

The following accessor method should be provided for its instance variable::

getEmployeeId( )

The Employee also has an abstract methods (which should be implemented by its child classes:

public void computePayAmount( )

public String toString()

toString method returns a string of the following format:

\nFirst name:\t\tJohn\n
Last name:\t\tSmith\n
Employee ID:\t\t5001\n
Pay Amount:\t\t$1,000.00\n

You should make use of the NumberFormat class (in java.text package) to format the pay amount.

FullTimeEmployee class

FullTimeEmployee is a subclass of Employee class.

The following constructor method should be provided:

public FullTimeEmployee (String firstname, String lastname, String id, double salary, double bonus)

The constructor of the parent class should be called using the first, second, and third parameters to initialize its first name, last name, and employee ID.

The following methods should be implemented:

public void computePayAmount()

It should set the value of the variable payAmount to be salary + bonus.

Also, the following method should be implemented:

public String toString()

The toString() method inherited from Employee class should be used to create a new string, and display a full time employee's information using the following format:

\nFull Time Employee:\n
First name:\t\tJohn\n
Last name:\t\tSmith\n
Employee ID:\t\t5001\n
Pay Amount:\t\t$1,000.00\n
Salary:\t\t\t$900.00\n
Bonus:\t\t\t$100.00\n\n

This toString method should make use of the toString method of the parent class.

PartTimeEmployee class

PartTimeEmployee is a subclass of Employee class. It has the following attribute in addition to the inherited ones:

Attribute name

Attribute type

Description

hourlyRate

double

The hourly rate of a part time employee

hours

int

The hours of a part time employee

The following constructor method should be provided:

public PartTimeEmployee (String firstname, String lastname, String id, double hourlyRate, int hours)

The constructor of the parent class should be called using the first, second, and third parameters to initialize its first name, last name, and employee Id. Then it should also initialize two more instance variables to 4th and 5th parameter values.

The following methods should be implemented:

public void computePayAmount()

It should set the value of the variable payAmount to be hourlyRate*hours.

Also, the following method should be implemented:

public String toString()

The toString() method inherited from Employee class should be used to create a new string, and display a full time employee's information using the following format:

\nPart Time Employee:\n
First name:\t\tJohn\n
Last name:\t\tSmith\n
Employee ID:\t\t5001\n
Pay Amount:\t\t$1,000.00\n
HourlyRate:\t\t$100.00\n
Hours:\t\t\t10\n\n

This toString method should make use of the toString method of the parent class.

EmployeeParser class

The EmployeeParser class is a utility class that will be used to create an object of a child class of Employee class from a parsable string. The EmployeeParser class object will never be instantiated. It must have the following method:

public static Employee parseStringToEmployee(String lineToParse)

The parseStringToEmployee method's argument will be a string in the following format:

For a full time employee

type:firstName:lastName:employeeID:salary:bonus

For a part time employee

type:firstName:lastName:employeeID:hourlyRate:hours

A real example of this string would be:

FullTime:Mary:Williams:200005:400000:50000

OR

PartTime:Sam:Brown:000002:25.25:10

This method will parse this string, pull out the information, create a new object of its corresponding child class of the Employee class with attributes of the object, and return it to the calling method. The type will always be present and always be either FullTime or PartTime. (It can be lower case or upper case) You may add other methods to the child classes in order to make your life easier.

Assignment5 class

In this assignment, download Assignment5.java file by clicking the link, and use it for your assignment. You need to add code to this file. The parts you need to add are written in the Assignment5.java file, namely for the cases "Add Employee", "Compute Pay", "Search for Employee", and "List Employees".

All input and output should be handled here. The main method should start by displaying this updated menu in this exact format:

Choice\t\tAction\n
------\t\t------\n
A\t\tAdd Employee\n
C\t\tCompute Pay \n
D\t\tSearch for Employee \n
L\t\tList Employees\n
Q\t\tQuit\n
?\t\tDisplay Help\n\n

Next, the following prompt should be displayed:

What action would you like to perform?\n

Read in the user input and execute the appropriate command. After the execution of each command, redisplay the prompt. Commands should be accepted in both lowercase and uppercase.

Add Employee

Your program should display the following prompt:

Please enter some employee information to add::\n

Read in the information and parse it using the employee parser.

Then add the new object returned by the employee parser method to the employee list.

Compute Pay Amount

Your program should call computePayAmount( ) method for each object of the employee list, to compute/update the pay amount for each employee.

Search for Employee

Your program should read in an employee id and search an employee of the id. If it is found, it should print "Employee found\n", and if not, then it should print "Employee not found". You need to set the boolean operation to true or false based of its search.

List Employees

List all employees in the employee list. Make use of toString method defined in the child classes of Employee class.

A real example is looked like this:

Part Time Employee:
First name:             Sam
Last name:              Brown
Employee ID:    000002
Pay Amount:     $0.00
HourlyRate:             $25.25
Hours:                  10
                    
                    
Full Time Employee:
First name:             Mary
Last name:              Williams
Employee ID:    200005
Pay Amount:             $0.00
Salary:                 $400,000.00
Bonus:                  $50,000.00
                    

If there is no bank account in the bank account list (the list is empty), then display following:

no employee\n

Quit

Your program should stop executing and output nothing.

Display Help

Your program should redisplay the "choice action" menu.

Invalid Command

If an invalid command is entered, display the following line:

Unknown action\n

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution