Add an HourlyPlusCommissionEmployee class to the PayrollSystem app by subclassing an existing class.
A HourlyPlusCommissionEmployee is a kind of CommissionEmployee with the following differences and specifications:
HourlyPlusCommissionEmployee earns money based on 2 separate calculations:
commissions are calculated by the CommissionEmployee base class hourly pay is calculated exactly the same as the HourlyEmployee class, but this is not inherited, it must be duplicated in the added class BasePlusCommissionEmployee inherits from CommissionEmployee and includes (duplicates) the details of SalariedEmployee.
Use this as an example of how to inherit from one class and still include details from another class as you write your class. Hint: the use of the word “Base” in BasePlusCommissionEmployee refers to the “base salary”, not the C# keyword “base” which refers to the base class.
IMPORTANT: you are not to make any changes whatsoever to any other source code files included in the project. You are only allowed to add a class file named HourlyPlusCommissionEmployee. This added file will include all your code. Any deviation from these instructions is incorrect and any changes to any other file will likely break the software. You are provided with a main driver program that includes code which already uses your new class and expects it to be there. All of this code must work correctly with your new added class. The application will not compile and run until you complete your piece. Use the driver program code and the comments for hints at what to do in the new class you add.
Here are the two files to adapt code and inherit from.
Commission employee:
// Fig. 12.7: CommissionEmployee.cs
// CommissionEmployee class that extends Employee.
using System;
namespace PayrollSystem
{
public class CommissionEmployee : Employee
{
private decimal grossSales; // gross weekly sales
private decimal commissionRate; // commission percentage
private string firstName;
private string lastName;
private string socialSecurityNumber;
public CommissionEmployee(string firstName, string lastName,
string socialSecurityNumber)
{
this.firstName = firstName;
this.lastName = lastName;
this.socialSecurityNumber = socialSecurityNumber;
}
// five-parameter constructor
public CommissionEmployee(string firstName, string lastName,
string socialSecurityNumber, decimal grossSales,
decimal commissionRate)
: base(firstName, lastName, socialSecurityNumber)
{
GrossSales = grossSales; // validates gross sales
CommissionRate = commissionRate; // validates commission rate
}
// property that gets and sets commission employee's gross
sales
public decimal GrossSales
{
get
{
return grossSales;
}
set
{
if (value < 0) // validation
{
throw new ArgumentOutOfRangeException(nameof(value),
value, $"{nameof(GrossSales)} must be >= 0");
}
grossSales = value;
}
}
// property that gets and sets commission employee's commission
rate
public decimal CommissionRate
{
get
{
return commissionRate;
}
set
{
if (value <= 0 || value >= 1) // validation
{
throw new ArgumentOutOfRangeException(nameof(value),
value, $"{nameof(CommissionRate)} must be > 0 and <
1");
}
commissionRate = value;
}
}
// calculate earnings; override abstract method Earnings in
Employee
public override decimal Earnings() => CommissionRate *
GrossSales;
// return string representation of CommissionEmployee
object
public override string ToString() =>
$"commission employee: {base.ToString()}\n" +
$"gross sales: {GrossSales:C}\n" +
$"commission rate: {CommissionRate:F2}";
}
}
Hourly employee
// Fig. 12.6: HourlyEmployee.cs
// HourlyEmployee class that extends Employee.
using System;
namespace PayrollSystem
{
public class HourlyEmployee : Employee
{
private decimal wage; // wage per hour
private decimal hours; // hours worked for the week
// five-parameter constructor
public HourlyEmployee(string firstName, string lastName,
string socialSecurityNumber, decimal hourlyWage,
decimal hoursWorked)
: base(firstName, lastName, socialSecurityNumber)
{
Wage = hourlyWage; // validate hourly wage
Hours = hoursWorked; // validate hours worked
}
// property that gets and sets hourly employee's wage
public decimal Wage
{
get
{
return wage;
}
set
{
if (value < 0) // validation
{
throw new ArgumentOutOfRangeException(nameof(value),
value, $"{nameof(Wage)} must be >= 0");
}
wage = value;
}
}
// property that gets and sets hourly employee's hours
public decimal Hours
{
get
{
return hours;
}
set
{
if (value < 0 || value > 168) // validation
{
throw new ArgumentOutOfRangeException(nameof(value),
value, $"{nameof(Hours)} must be >= 0 and <= 168");
}
hours = value;
}
}
// calculate earnings; override Employee’s abstract method
Earnings
public override decimal Earnings()
{
if (Hours <= 40) // no overtime
{
return Wage * Hours;
}
else
{
return (40 * Wage) + ((Hours - 40) * Wage * 1.5M);
}
}
// return string representation of HourlyEmployee object
public override string ToString() =>
$"hourly employee: {base.ToString()}\n" +
$"hourly wage: {Wage:C}\nhours worked: {Hours:F2}";
}
}
Program screenshot:
Sample output
screenshot:
Code to copy:
/******************File name:
Employee.cs******************/using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PayrollSystem
{
public abstract class Employee
{
public string FirstName { get; private set; }
public string LastName { get; private set; }
public string SocialSecurityNumber { get; private set; }
public Employee(string first, string last, string ssn)
{
FirstName = first;
LastName = last;
SocialSecurityNumber = ssn;
}
public abstract decimal Earnings();
public override string ToString()
{
return string.Format("{0} {1}\nsocial secuirity number: {2}",
FirstName, LastName, SocialSecurityNumber);
}
}
}
/******************File name:
SalariedEmployee.cs******************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PayrollSystem
{
public class SalariedEmployee : Employee
{
private decimal weeklySalary { get; set; }
public decimal WeeklySalary
{
get
{
return weeklySalary;
}
set
{
weeklySalary = ((value >= 0) ? value : 0);
}
}
public SalariedEmployee(string first, string last, string ssn,
decimal weekSal) : base(first, last, ssn)
{
WeeklySalary = weekSal;
}
public override decimal Earnings()
{
return WeeklySalary;
}
public override string ToString()
{
return string.Format("salaried employee: {0}\n{1}: {2:c}",
base.ToString(), "weekly salary", WeeklySalary);
}
}
}
/******************File name:
HourlyEmployee.cs******************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PayrollSystem
{
public class HourlyEmployee : Employee
{
private decimal hours;
private decimal wage;
public decimal Wage
{
get
{
return wage;
}
set
{
wage = value >= 0 ? value : 0;
}
}
public decimal Hours
{
get
{
return hours;
}
set
{
hours = (value >= 0) && (value <= 168) ? value :
0;
}
}
public HourlyEmployee(string first, string last, string ssn,
decimal hoursWorked, decimal hourlyWage) : base(first, last,
ssn)
{
Hours = hoursWorked;
Wage = hourlyWage;
}
public override decimal Earnings()
{
if (hours <= 40)
{
return wage * hours;
}
else
{
return (40 * wage) + (hours - 40) * wage * 1.5M;
}
}
public override string ToString()
{
return string.Format("hourly employee: {0}\n{1}: {2:C}\n{3}:
{4:F2}", base.ToString(), "hourly wage", Wage, "hours worked",
Hours);
}
}
}
/******************File name:
CommissionEmployee.cs******************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PayrollSystem
{
public class CommissionEmployee : Employee
{
private decimal grossSales;
private decimal commissionRate;
public decimal GrossSales
{
get
{
return grossSales;
}
set
{
grossSales = value >= 0 ? value : 0;
}
}
public decimal CommissionRate
{
get
{
return commissionRate;
}
set
{
commissionRate = (value > 0 && value < 1) ? value :
0;
}
}
public CommissionEmployee(string first, string last, string ssn,
decimal grossSal, decimal comRate) : base(first, last, ssn)
{
GrossSales = grossSal;
CommissionRate = comRate;
}
public CommissionEmployee(string first, string last, string ssn)
: base(first, last, ssn)
{
}
public override decimal Earnings()
{
return CommissionRate * GrossSales;
}
public override string ToString()
{
return string.Format("{0}: {1}\n{2}: {3:C}\n{4}: {5:F2}",
"commission employee", base.ToString(), "gross sales", GrossSales,
"commission rate", CommissionRate);
}
}
}
/******************File name:
PayrollSystem.cs******************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PayrollSystem
{
public class BasePlusCommissionEmployee : CommissionEmployee
{
private decimal baseSalary;
public decimal BaseSalary
{
get
{
return baseSalary;
}
set
{
baseSalary = value >= 0 ? value : 0;
}
}
public BasePlusCommissionEmployee(string first, string last, string
ssn, decimal grossSal, decimal comRate, decimal bSalary) :
base(first, last, ssn, grossSal, comRate)
{
BaseSalary = bSalary;
}
public override string ToString()
{
return string.Format("base-salaried {0}; base salary: {1:C}",
base.ToString(), BaseSalary);
}
public override decimal Earnings()
{
return BaseSalary + base.Earnings();
}
}
}
/*****************File name:
HourlyPlusCommissionEmployee.cs************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PayrollSystem
{
public class HourlyPlusCommissionEmployee :
CommissionEmployee
{
private decimal hours;
private decimal wage;
public decimal Wage
{
get
{
return wage;
}
set
{
wage = value >= 0 ? value : 0;
}
}
public decimal Hours
{
get
{
return hours;
}
set
{
if ((value >= 0) && (value <= 168))
{
hours = 0;
}
else
{
hours = value;
}
}
}
public HourlyPlusCommissionEmployee(string first, string last,
string ssn, decimal hoursWorked, decimal hourlyWage, decimal
grossSal, decimal comRat) : base(first, last, ssn, grossSal,
comRat)
{
Hours = hoursWorked;
Wage = hourlyWage;
}
public override decimal Earnings()
{
if (hours <= 40)
{
return wage * hours;
}
else
{
return (40 * wage) + (hours - 40) * wage * 1.5M +
base.Earnings();
}
}
public override string ToString()
{
return string.Format("hourly plus commission employee: {0}\n{1}:
{2:C}\n{3}: {4:F2}", base.ToString(), "hourly wage", Wage, "hours
worked", Hours);
}
}
}
/******************File name:
Program.cs******************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PayrollSystem
{
class Program
{
static void Main(string[] args)
{
SalariedEmployee salariedEmployee = new SalariedEmployee("John",
"Smith", "111-11-1111", 800.00M);
HourlyEmployee hourlyEmployee = new HourlyEmployee("Karen",
"Price", "222-22-2222", 16.75M, 40.0M);
CommissionEmployee commissionEmployee = new
CommissionEmployee("Sue", "Jones", "333-33-3333", 10000.00M,
.06M);
BasePlusCommissionEmployee basePlusCommissionEmployee = new
BasePlusCommissionEmployee("Bob", "Lewis", "444-44-4444", 5000.00M,
.04M, 300.00M);
Console.WriteLine("Employees processed individually:\n");
HourlyPlusCommissionEmployee hourlyPlusCommissionEmployee = new
HourlyPlusCommissionEmployee("Alice", "Rob", "555-55-5555",
190.00M, 3.04M, 100.00M, .06M);
Console.WriteLine("Employees processed hourly:\n");
Console.WriteLine("{0}\nearned: {1:C}\n", salariedEmployee,
salariedEmployee.Earnings());
Console.WriteLine("{0}\nearned: {1:C}\n", hourlyEmployee,
hourlyEmployee.Earnings());
Console.WriteLine("{0}\nearned: {1:C}\n", commissionEmployee,
commissionEmployee.Earnings());
Console.WriteLine("{0}\nearned: {1:C}\n",
basePlusCommissionEmployee,
basePlusCommissionEmployee.Earnings());
Console.WriteLine("{0}\nearned: {1:C}\n",
hourlyPlusCommissionEmployee,
hourlyPlusCommissionEmployee.Earnings());
Employee[] employees = new Employee[5];
employees[0] = salariedEmployee;
employees[1] = hourlyEmployee;
employees[2] = commissionEmployee;
employees[3] = basePlusCommissionEmployee;
employees[4] = hourlyPlusCommissionEmployee;
foreach (var currentEmployee in employees)
{
Console.WriteLine(currentEmployee);
if (currentEmployee is BasePlusCommissionEmployee)
{
//downcast Employee reference to BasePlusCommissionEmployee
reference
BasePlusCommissionEmployee employee =
(BasePlusCommissionEmployee)currentEmployee;
employee.BaseSalary *= 1.10M;
Console.WriteLine("new base salary with 10% increase is: {0:C}",
employee.BaseSalary);
}
Console.WriteLine("earned{0:C}\n",
currentEmployee.Earnings());
}
for (int j = 0; j < employees.Length; j++)
Console.WriteLine("Employee {0} is a {1}", j,
employees[j].GetType());
Console.ReadLine();
}
}
}
Add an HourlyPlusCommissionEmployee class to the PayrollSystem app by subclassing an existing class. A HourlyPlusCommissionEmployee is...
I need help in getting the second output to show both the commission rate and the earnings for the String method output package CompemsationTypes; public class BasePlusCommissionEmployee extends CommissionEmployee { public void setGrossSales(double grossSales) { super.setGrossSales(grossSales); } public double getGrossSales() { return super.getGrossSales(); } public void setCommissionRate(double commissionRate) { super.setCommissionRate(commissionRate); } public double getCommissionRate() { return super.getCommissionRate(); } public String getFirstName() { return super.getFirstName(); } public String getLastName() { return super.getLastName(); } public String getSocialSecurityNumber() { return super.getSocialSecurityNumber(); } private...
HOW TO FiX EXCEPTIONS??? In order to populate the array, you will need to split() each String on the (,) character so you can access each individual value of data. Based on the first value (e.g., #) your method will know whether to create a new Manager, HourlyWorker, or CommissionWorker object. Once created, populate the object with the remaining values then store it in the array. Finally, iterate through the array of employees using the enhanced for loop syntax, and...
In the processLineOfData method, write the code to handle case "H" of the switch statement such that: • An HourlyEmployee object is created using the firstName, lastName, rate, and hours local variables. Notice that rate and hours need to be converted from String to double. You may use parseDouble method of the Double class as follows: Double.parseDouble(rate) Call the parsePaychecks method in this class passing the Hourly Employee object created in the previous step and the checks variable. Call the...
In the processLineOfData, write the code to handle case "H" of the switch statement such that: An HourlyEmployee object is created using the firstName, lastName, rate, and hours local variables. Notice that rate and hours need to be converted from String to double. You may use parseDouble method of the Double class as follows: Double.parseDouble(rate) Call the parsePaychecks method in this class passing the HourlyEmployee object created in the previous step and the checks variable. Call the findDepartment method...
a database of employees that corresponds to the
employee-payroll hierarchy is provided (see employees.sql to create
the employees for a MySQL database). Write an application that
allows the user to:
Add employees to the employee table.
Add payroll information to the appropriate table for each new
employee. For example, for a salaried employee add the payroll
information to the salariedEmployees table
1 is the entity-relationship diagram for the
employees database
Figure 1: Table relationships in the employees database [1].
Add...
Java
Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEmployee, HourlyEmployee which extend the Employee class and implements that abstract method. A Salary Employee has a salary, a Commision Employee has a commission rate and total sales, and Hourly Employee as an hourly rate and hours worked Software Architecture: The Employee class is the abstract super class and must be instantiated by one of...
8.26
Encapsulate the Name class. Modify the existing code shown below
to make its fields private, and add appropriate accessor methods to
the class named getFirstName, getMiddleInitial, and
getLastName.
code:
class Name {
private String firstName;
private String middleNames;
private String lastName;
//Constructor method
public Name(String firstName, String middleNames, String
lastName)
{
this.firstName = firstName;
this.middleNames = middleNames;
this.lastName = lastName;
}
//Accessor for firstName
public String getFirstName()
{
return firstName;
}
//Accessor for middleNames
public String getMiddlesNames()...
By editing the code below to include composition, enums, toString; must do the following: Prompt the user to enter their birth date and hire date (see Fig. 8.7, 8.8 and 8.9 examples) in addition to the previous user input Create a new class that validates the dates that are input (can copy date class from the book) Incorporate composition into your class with these dates Use enums to identify the employee status as fulltime (40 or more hours worked for...
Use Visual Studio for the following: Add an HourlyPlusCommissionEmployee class to the PayrollSystem app by subclassing an existing class. A HourlyPlusCommissionEmployee is a kind of CommissionEmployee with the following differences and specifications: HourlyPlusCommissionEmployee earns money based on 2 separate calculations: commissions are calculated by the CommissionEmployee base class hourly pay is calculated exactly the same as the HourlyEmployee class, but this is not inherited, it must be duplicated in the added class BasePlusCommissionEmployee inherits from CommissionEmployee and includes (duplicates) the...