Question

In: Computer Science

You are hired by a small company to design a payroll system to perform payroll calculations based on the type of employee (manager and hourly worker)

A Payroll System (it is worth a total of 20 points)

You are hired by a small company to design a payroll system to perform payroll calculations based on the type of employee (manager and hourly worker). Managers are paid a fixed weekly salary regardless of the number of hours worked; hourly workers are paid by the the hours and receives overtime pay (50% more overtime pay, but overtime cannot exceed 20 hours per week).

Both managers and hourly workers have something in common. For example, their names. However, the way each person’s earnings are calculated depends on the type of employee, so you decided to define the common features in a more generic class named Employee, then create two subclasses, Manager and HourlyWorker for manager and hourly worker, respectively.

Design an abstract class named Employee.java with the following data members and methods:

Data members: firstName, lastName

All getter and setter methods

Constructor takes first name and last name as parameters.

toString() methods to return name (Steve Davis, for example)

earnings() to return earnings (double) (think about if it is appropriate to be defined as abstract)

Create Manager.java and make it a subclass of Employee. This class should have its own data member: weeklySalary (double):

Getter and setter method for the new data member

Implement earnings() method to return weekly salary (be sure to validate weekly salary, the salary range is between $800 and $2000, for any other numbers, assign 0)

Override toString() method to type of employee followed by manage name. For example, Manage: Steve Davis

Create HourlyWorker.java and make it a subclass of Employee:

Data members: wage (per hours), hours (hours worked for a week)

Getter and setter methods (remember, number of hours worked per week cannot exceed 60 hours. If a number over 60 is entered, it will be reduced to 60 hours; wage range: $25 - $50, all other numbers are considered as invalid and assign default wage, which is $35 per hour)

Implements earnings() method

Override toString() to return employee type and name (for example, Hourly Worker: John Kanet)

Write a tester class named Tester.java to test your payroll system. Your tester class will read data file (employee.txt) and create employee objects, then print payment for each employee.

The sample input file:

#Steve Davis

1200

*John Kanet

35.5

50

*Matthew Williams

25

40

#Alex Bowers

5000

*Atanas Radenski

-45

80

a line starting with # is a manager, followed by weekly salary; a line starting with * is a hourly worker, followed by wage and hours.

Sample output:

Manager: Steve Davis

Earned: 1200.0

Hourly Worker: John Kanet

Earned: 1952.5

Hourly Worker: Matthew Williams

Earned: 1000.0

Manager: Alex Bowers

Earned: 0.0

Hourly Worker: Atanas Radenski

Earned: 2450.0

Solutions

Expert Solution

//Employee.java
//Employee class that contains first and last names
//abstract method for earnings
public abstract class Employee
{
   private String firstName;
   private String lastName;
  
   public Employee(String firstName, String lastName)
   {
       this.firstName=firstName;
       this.lastName=lastName;
   }
  
   public void setFirstName(String firstName)
   {
       this.firstName=firstName;
   }
   public String getFirstName()
   {
       return firstName;
   }
   public void setLastName(String lastName)
   {
       this.lastName=lastName;
   }
   public String getLastName()
   {
       return lastName;
   }
  
   @Override
   public String toString()
   {      
       return firstName+" "+lastName;
   }
   public abstract double earnings();
  
}

--------------------------------------------------------------------------------------------------


//Manager.java extends the Employee
public class Manager extends Employee
{
   private double weeklySalary;
   //Manager class constructor
   public Manager(String firstName, String lastName,
           double weeklySalary)
   {
       super(firstName, lastName);
       if(weeklySalary>800 && weeklySalary<2000)
           this.weeklySalary=weeklySalary;
       else
           this.weeklySalary=0;
   }
  
   @Override
   public String toString() {      
       return "Manager : "+super.toString()+"\n"+earnings();
   }
   //Overird earnings method that return weekly salary
   @Override
   public double earnings() {      
       return weeklySalary;
   }  
}

--------------------------------------------------------------------------------------------------

//HourlyWorker.java
//extends the employee class
public class HourlyWorker extends Employee
{

   private double wage;
   private double hours;
   public HourlyWorker(String firstName, String lastName,
           double wage, double hours)
   {
       super(firstName, lastName);
       setWage(wage);
       setHours(hours);
       this.hours=hours;      
   }
  
   public void setWage(double wage)
   {
       if(wage>=25 && wage<=50)
           this.wage=wage;
       else
           //Set default value if wage is out of range
           this.wage=35;
   }
  
   public void setHours(double hours)
   {
       if(hours<60)
           this.hours=hours;
       else
           //Set default value if hours is out of range
           this.hours=60;
   }
  
   @Override
   public String toString() {      
       return "Hourly Worker : "+super.toString()+"\n"+earnings();
   }
  
   @Override
   public double earnings() {      
       return wage*hours;
   }
  
  
}

--------------------------------------------------------------------------------------------------

/**
* The java program Tester that reads the employee.txt file
* and reads employee data into an array of Employee type
* and prints the employees to console.
* */
//Tester.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Tester
{
   public static void main(String[] args)
   {
       String file="employee.txt";

       Scanner filescanner=null;
       String firstName;
       char ch;
       String name;      
       double earn=0;
       String lastName;
       Employee[] emps=new Employee[5];
       int index=0;

       try
       {
           //ope a file
           filescanner=
                   new Scanner(new File(file));

           //read file until end of the file
           while(filescanner.hasNextLine())
           {

               firstName=filescanner.next();
               ch=firstName.charAt(0);
               double wage,hours;
               switch(ch)
               {
               case '#':
                   name=firstName.substring(1, firstName.length());
                   lastName=filescanner.next();
                   earn=filescanner.nextDouble();
                   emps[index]=new Manager(name, lastName, earn);
                   break;

               case '*':
                   name=firstName.substring(1, firstName.length());
                   lastName=filescanner.next();
                   wage=filescanner.nextDouble();
                   hours=filescanner.nextDouble();
                   emps[index]=new HourlyWorker(name, lastName, wage, hours);              
                   break;
               }
              
               index++;
           }
          
          
           //print employees to console
           for (Employee employee : emps)
           {
               System.out.println(employee.toString());
           }
          
       }
       catch (FileNotFoundException e)
       {
           System.out.println(e.getMessage());
       }
   }
}

--------------------------------------------------------------------------------------------------

Input file : employee.txt

#Steve Davis
1200
*John Kanet
35.5
50
*Matthew Williams
25
40
#Alex Bowers
5000
*Atanas Radenski
-45
80

--------------------------------------------------------------------------------------------------

Sample output:

Manager : Steve Davis
1200.0
Hourly Worker : John Kanet
1775.0
Hourly Worker : Matthew Williams
1000.0
Manager : Alex Bowers
0.0
Hourly Worker : Atanas Radenski
2800.0


Related Solutions

Assume you are a new employee at Payroll Inc. a company which process payroll, advises small...
Assume you are a new employee at Payroll Inc. a company which process payroll, advises small businesses on payroll issues, and remits all withheld funds to the government along with payroll forms required. Processing payroll and completing forms is a routine process which is repeated for each client and payroll period. Payroll advising is unique to each client. In your initial post discuss the aspects of Payroll Inc.'s processes that lend themselves to process costing and which processes would more...
You are the manager of a payroll system. Your company is going to replace the legacy...
You are the manager of a payroll system. Your company is going to replace the legacy payroll system with a more robust, Web-based version. Suggest two approaches that would minimize downtime and interruption to the payroll process. Provide specific examples to support your response. Propose a process for evaluating the success of the new system and a procedure for implementing software fixes and enhancements. Provide specific examples to support your response.
A student hourly employee does small secretarial projects. Her manager wants to learn about the relationship...
A student hourly employee does small secretarial projects. Her manager wants to learn about the relationship between the number of projects (y) the student completes in a day and the number of hours (x) she works in a day. A random sample of nine days provided the following information: Working Hours (X) 1 2 3 4 4 6 7 7 8 Number of Projects (Y) 2 3 5 6 5 8 9 8 10 a) define variable types (circle all...
A student hourly employee does small secretarial projects. Her manager wants to learn about the relationship...
A student hourly employee does small secretarial projects. Her manager wants to learn about the relationship between the number of projects (y) the student completes in a day and the number of hours (x) she works in a day. A random sample of nine days provided the following information: Working Hours # of projects 1 2 2 3 3 5 4 6 4 5 6 8 7 9 7 8 8 10 a) Define variable types [Choose all that applies]:...
You have just been hired as the payroll manager of a mid-sized manufacturing company. You notice...
You have just been hired as the payroll manager of a mid-sized manufacturing company. You notice that the time cards are paper documents that the employee submit at the end of the week into an open cardboard box outside of your office. The time cards contain the employee's name, pay rate, social security number, and division where he/she works. You ask the only employee currently in the payroll department, where the payroll files are and she points you to another...
Your professional company is hired to perform a hydrologic-hydraulic study needed for the design of a...
Your professional company is hired to perform a hydrologic-hydraulic study needed for the design of a new bridge. The 75-year historical data (annual maximum series) collected from a nearby station at a river was used to develop the statistical parameters. The expected project life of the bridge is 50 years. Following bridge safety regulations, the 500-year flood (based on annual maximum data series) is used for design purposes. The bridge construction will require five (5) years of work inside the...
The owners of a small manufacturing concern have hired a manager to run the company with...
The owners of a small manufacturing concern have hired a manager to run the company with the expectation that (s)he will buy the company after five years. The goal of the owners in making this hire is to find the appropriate manager that will increase profits substantially. Compensation of the new manager is a flat salary plus 50% of first $200,000 of profit, and then 5% of profit over $200,000. Purchase price for the company is set as 4.5 times...
You have been hired as the financial manager to design a new Powerball jackpot. The marketing...
You have been hired as the financial manager to design a new Powerball jackpot. The marketing team, after a thorough market research, has found that offering an infinite annuity would attract a new market segment. This program is expected to attract at least 2,000,000 participants. The company is planning to sell each ticket for $2 each. The cash flow is as follows: During the first year, every 6-months, $100,000 will be given to the winner For the second year and...
You have just been hired as the marketing manager at a small retail clothing store. In...
You have just been hired as the marketing manager at a small retail clothing store. In the past, the store has done all the inventory purchasing, marketing and sales promotions based on intuition. Of course, as a marketing professional, you know that this is not the best strategy. You must convince your new boss to use a more empirical approach based on marketing metrics. Write a few organized paragraphs explaining to your boss what marketing metrics should be used and...
You are a Financial Manager CRC Company Ltd. in calculations of the risk values, your Company...
You are a Financial Manager CRC Company Ltd. in calculations of the risk values, your Company applies a VaR system at 99% (relative) VaR values on a daily basis. Over the last 500 trading days (two years) there have been five occasions when the VaR values have been breached. A subordinate comes to you with some serious concerns in relation to the current VaR calculations, arguing that they wrongly represent correlations in behavior occurring at times when the markets make...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT