Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Your task is to implement a solution to the problem described below. Your work must include the following: Your version of all the .java files

Your task is to implement a solution to the problem described below. Your work must include the following:

  • Your version of all the .java files that you worked on:
    • PayrollClient.java
    • Payroll.java
    • StaffMember.java
    • Executive.java
    • HourlyEmployee.java
    • Volunteer.java
  • Output of your program saved in a text file
  • Must include your name in each file that you are submitting.

You need to:

  • use Scanner for the input
  • use System.out.print, System.out.println, System.out.printf for output
  • implement classes and methods as suggested in the attached UML class diagram
  • include as many comments as are necessary to describe what the given code segment is doing

IMPORTANT:

  • Have only one return statement per value returning method

Problem Description

A company has three types of staff members: executive, hourly employee, and volunteer:

  • Each staff member has: name, address, phone number, and social security number.
  • Executive has two additional attributes: yearly salary, and bonus that is assigned at the end of the month.
  • Hourly employee has different additional attributes: pay rate per hour, and hours worked in a month (assigned at the end of the month).
  • Volunteer has no additional attributes.

Your Task

Write a program to calculate monthly payroll.

The staff data is stored in a text file called staff.txt. Each line consists of five or six tokens: type of staff, name, address, phone number, social security number, and pay (NOTE: pay is not present for the Volunteer).

setSsn method throws InvalidParameterException if the given social security number does not match the pattern of DDD-DD-DDDD (use matches method for validation).

Payroll constructor creates the staffList ArrayList and populates the list from the staff.txt file. The constructor handles InputMismatchException, NoSuchElementException and InvalidParameterException.

prepareForPayDay method:

  • for each executive, awards a bonus between $500 and $5000 (randomly generated )
  • for each hourly employee, adds hours between 20 and 100 (randomly generated)
  • NOTE:
    • use for-each loop to traverse the staffList,
    • utilize instanceof operator when traversing the staffList, to check the type of the object
    • use casting to tell java virtual machine the precise type of the object for example:

Executive exec = (Executive) staffMember;

processPayroll method calls calculatePayment method for each staff member to generate an array of pay (must utilize a regular for loop)

displayStaffData method prints all staff data

The payment calculation algorithm depends on the type of the staff member:

  • Executive bonus is added to the monthly salary
  1. HourlyEmployee number of hours worked multiplied by the hourly rate
  2. Volunteer gets no payment.

Start with the attached UML diagram and draw a memory diagram depicting how data is organized. Next, finish skeletons for each class. Please note that PayrollClient.java is fully implemented.

Analyze the Sample Run below to better understand the projects algorithm and ensure that your program matches the sample run.

UML Class Diagram

image text in transcribed

Sample Run of the program

---> Reading staff data from the file

processing record: Tony,123 Main Line,555-0469,123-45-6789,222423.07

>>>>> InvalidParameterException in staff record - The employee type "Tony" is not supported - record: "Tony,123 Main Line,555-0469,123-45-6789,222423.07" ignored

processing record: Executive,Anthony,123 Main Line,555-0469,123-45-6789,222423.07

processing record: Executive,Paulie,456 Off Line,555-0101,987-65-4321,123456.78

processing record: Executive,Mark,456 Off Line,555-0101,123456.78,987-65-4321

>>>>> InputMismatchException in staff record - incompatible data - record: "Executive,Mark,456 Off Line,555-0101,123456.78,987-65-4321" ignored

processing record: Hourly,Victor,789 Off Rocker,555-0000,010-20-3040,69.23

processing record: Hourly,Michael,678 Fifth Ave.,555-0690,958-47-3625,100.55

processing record: Hourly,Mary,6 Sixth Ave.,555-6666,123456789,160.66

>>>>> InvalidParameterException in staff record - The SSN must follow the pattern DDD-DD-DDDD - record: "Hourly,Mary,6 Sixth Ave.,555-6666,123456789,160.66" ignored

processing record: Hourly,Carl,6 Sixth Ave.,555-6666,123456789

>>>>> NoSuchElementException in staff record - missing data - record: "Hourly,Carl,6 Sixth Ave.,555-6666,123456789" ignored

processing record: Hourly,Ellen,4 Rainbow,555-1234,310-28-3145,157.65

processing record: Monthly,Jillian,123 Main Line,555-0469,123-45-6789,2224.07

>>>>> InvalidParameterException in staff record - The employee type "Monthly" is not supported - record: "Monthly,Jillian,123 Main Line,555-0469,123-45-6789,2224.07" ignored

processing record: Hourly,Tomas, 678 Seven Ave.,555-2692,321-44-6622,95.50

processing record: Volunteer,Adrianna,987 Sunset Blvd.,555-8374,576-23-5689

processing record: Volunteer,Benny,321 Sunflower Lane,555-7282,375-22-9056

---> Finished reading from the file

---> Preparing data for pay day

*** The current staff data for the month of December 2018 ***

The company has 8 employees

--- Executive --- Name: Anthony

Address: 123 Main Line

Phone: 555-0469

Social Security Number: 123-45-6789

Yearly salary of: $222423.07

Bonus: $1103.00

--- Executive --- Name: Paulie

Address: 456 Off Line

Phone: 555-0101

Social Security Number: 987-65-4321

Yearly salary of: $123456.78

Bonus: $4628.00

--- Hourly Employee --- Name: Victor

Address: 789 Off Rocker

Phone: 555-0000

Social Security Number: 010-20-3040

Current hours: 55 at rate of: $69.23

--- Hourly Employee --- Name: Michael

Address: 678 Fifth Ave.

Phone: 555-0690

Social Security Number: 958-47-3625

Current hours: 42 at rate of: $100.55

--- Hourly Employee --- Name: Ellen

Address: 4 Rainbow

Phone: 555-1234

Social Security Number: 310-28-3145

Current hours: 36 at rate of: $157.65

--- Hourly Employee --- Name: Tomas

Address: 678 Seven Ave.

Phone: 555-2692

Social Security Number: 321-44-6622

Current hours: 63 at rate of: $95.50

--- Volunteer --- Name: Adrianna

Address: 987 Sunset Blvd.

Phone: 555-8374

Social Security Number: 576-23-5689

--- Volunteer --- Name: Benny

Address: 321 Sunflower Lane

Phone: 555-7282

Social Security Number: 375-22-9056

*** End of the list ***

---> Processing the payroll

*** Payroll for the month of December 2018 ***

1. Anthony ---> 19,638.26

2. Paulie ---> 14,916.07

3. Victor ---> 3,807.65

4. Michael ---> 4,223.10

5. Ellen ---> 5,675.40

6. Tomas ---> 6,016.50

7. Adrianna ---> 0.00

8. Benny ---> 0.00

***********************************************

Process finished with exit code 0

PayrolClient main(String) void create cExecutive % bonus double double int int int Payroll ArrayListeStaffMember> String String String 1staffList f& yearly MIN BONUS MAX BONUS Volunteer m Volunteer(String, String, String, String) m calculatePayment) mtoString) HOURLY EXECUTIVE VOLUNTEER Payrol(Scanner) > 1e6 NUMBER-OF-MONTHS create m Executive(String, String, String, String, double) mawardBonus(double) double void doublel mgetStaffList0 ArrayList void double boolean String String mprepareForPayDay0) mprocessPayrolI) calculatePayment) mequals(Object) toString() void n display Staff Data0 create e StaffMember f& name String String String String CHourlyEmployee address int double int int f&phone payRate ssn " MIN-HOURS b MAXHOURS m Staff Member(String, String, String, String) m getName) m getAddress) String String String void String boolean String double - mHourlyEmployee(String, String, String, String, double) mcalculatePayment0 mtoString0 void double boolean String m addHours(int) msetSsn(String) mgetSsn0 mequals(Object) m toString) mcalculatePayment 0 mequals (Object)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions