Question
Assignment 4:C# C# C# Activities: 1. Rewrite the solution to assignment 3 with this new UML so to use polymorphism via interface according to the
Assignment 4:C# C# C#
Activities:
1. Rewrite the solution to assignment 3 with this new UML so to use polymorphism via interface according to the following UML class diagram to solve the payroll problem:
-------------------------------------------------------------------------------------------------
this is my code in as3:
using System;
namespace AsOPP {
//StaffMember: public abstract class StaffMember { // attributes protected string name; protected string address; protected string phone;
/// Constructor public StaffMember(string eName, string eAddress, string ePhone) { this.name = eName; this.address = eAddress; this.phone = ePhone; }
/// String representation of StaffMember public override string ToString() { return "Name: " + name + " Address: " + address + " Phone: " + phone; } // abstract method abstract public double Pay();
}
//Employee: public class Employee : StaffMember { // attributes protected string socialSecurityNumber; protected double payRate;
/// Constructor public Employee(string eName, string eAddress, string ePhone, string socSecNumber, double rate) : base(eName, eAddress, ePhone) { this.socialSecurityNumber = socSecNumber; this.payRate = rate; }
public override string ToString() { return base.ToString() + " Social Security Number: " + socialSecurityNumber + " Payrate: " + payRate; }
public override double Pay() { return payRate; }
}
//Volunteer:
public class Volunteer : StaffMember { /// Constructor public Volunteer(string eName, string eAddress, string ePhone) : base(eName, eAddress, ePhone) { }
public override string ToString() { return base.ToString(); }
public override double Pay() { return 0; } }
//Hourly: public class Hourly : Employee { // attribute private int hourlyWorked;
/// Constructor public Hourly(string eName, string eAddress, string ePhone, string socSecNumber, double rate) : base(eName, eAddress, ePhone, socSecNumber, rate) { hourlyWorked = 0; }
/// Adds moreHours to the hoursWorked
public void addHours(int moreHours)
{
hourlyWorked += moreHours;
}
public override string ToString()
{
return base.ToString();
}
///
public override double Pay()
{
return base.payRate * hourlyWorked;
}
}
//Executive:
public class Executive : Employee
{
// attribute
private double bonus;
/// Constructor
public Executive(string eName, string eAddress, string ePhone, string socSecNumber, double rate) : base(eName, eAddress, ePhone, socSecNumber, rate)
{
bonus = 0;
}
/// Award bonus
public void awardBonus(double execBonus)
{
bonus = execBonus;
}
/// Computes payRate
public override double Pay()
{
return base.Pay() + bonus;
}
}
//Staff:
public class Staff
{
// attributes
private StaffMember[] staffList;
private int totalStaff;
/// Constructor
public Staff()
{
// get total number of Staffs
Console.Write("Enter number of staffs: ");
totalStaff = Convert.ToInt32(Console.ReadLine());
// declare the staffList to the user entered input
staffList = new StaffMember[totalStaff];
// assign values to the list
staffList[0] = new Executive("Sam", "123 Main Line", "555-0469", "123-45-6789", 2423.07);
staffList[1] = new Employee("Salma", "456 Off Line", "555-0101", "987-65-4321", 1246.15);
staffList[2] = new Hourly("Diane", "678 Fifth Ave.", "555-0690", "958-47-3625", 10.55);
staffList[3] = new Volunteer("Khalid", "321 Dud Lane", "555-7282");
((Executive)staffList[0]).awardBonus(500.00);
((Hourly)staffList[2]).addHours(40);
}
public void payday()
{
// iterate till the list of staff
for (int count = 0; count
{
Console.WriteLine(staffList[count]);
Console.WriteLine("Amount: " + staffList[count].Pay());
Console.WriteLine("##################################");
}
}
}
//Firm:
public class Firm
{
static void Main(string[] args)
{
// Create an instance of Staff
Staff staff = new Staff();
Console.WriteLine(" Staff List");
// Print the details
staff.payday();
}
}
}
Staff minterfaces stafPay Firm staffl ist stafPayl Main (args: stringill + Pay(): double + create Staff + Payday 0 StaffMember # name: string # address: string #phone: string + create Stat Member (cName : string. cAddress : string. c Phone : string) + ToString : string AA Volunteer 1 1 1 1 1 ! 1 Employee socialSecurilyNurnber string * payRate: double + creales Employee (eName : string, eAddress : String, e Phone : string, socSecNumber : string, rate : double) - ToString 0:string - Pay 0: double + creales Volunteer (eName : String, eAduress: string, e Phone: string) + Pay 0: double Executive bonus: double Hourly - hoursWorked: int + screate Hourly (eName : string, eAddress : string, e Phone : string, socSecNumber:string, rate : double) + addHours (moreHours: inu) + Pay O: double + ToString O: string + acreate Executive (eName : string, eAddress : string, e Phone: string, sodSec Number : string, rate : double) + awardBonus (execBonus : double) + Pay O: doubleStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started