The objective of the lab is to take the UML Class diagram and enhance last week\
ID: 3645310 • Letter: T
Question
The objective of the lab is to take the UML Class diagram and enhance last week's Employee class by making the following changes: Convert the Employee class to an abstract class Add an abstract method called CalculateNetPay to the Employee class In both the Salaried and Hourly classes implement the CalculateNetPay methodSTEP 1: Modify the Employee Class Modify the class declaration of the Employee class to specify that the Employee class is an abstract class Declare an abstract method called CalculateNetPay that returns a double value. Modify the ToString Method to include the weekly net pay in currency format.
STEP 2: Modify the Salaried Class Add a double constant called TAX_RATE and set the value to .73 Implement the CalculateNetPay method by multiplying the weekly pay by the tax rate.
STEP 3: Modify the Hourly Class Add a double constant called TAX_RATE and set the value to .82 Implement the CalculateNetPay method by multiplying the weekly pay by the tax rate.
STEP 4: Create the Main Program Change the employeeList array to only hold two objects Create one Hourly employee object and store it in the array. Create one Salaried employee object and store it in the array. As you did in the Week 5 lab, prompt for and collect the information for each of the objects. Note: iterating through the array should not require any changes from the previous iteration of the project--but make sure that the loop stays within the bounds of the array.
*******Existing Code that needs modified below***********
The salaried and hourly class are in the Employee class. There are 7 classes all together, I went ahead and included all of them.
Employee.cs
class Employee
{
// Attributes
protected const string DEFAULT_NAME = "NOT GIVEN";
protected const char DEFAULT_GENDER = 'U';
protected const int MIN_DEPENDENTS = 0;
protected const int MAX_DEPENDENTS = 10;
protected const double MIN_SALARY = 0;
protected const double MAX_SALARY = 200000;
protected string firstName = DEFAULT_NAME;
protected string lastName = DEFAULT_NAME;
protected char gender = DEFAULT_GENDER;
protected int dependents = 0;
protected double annualSalary = 2000;
protected static int numEmployees = 0;
protected string employeeType;
protected Benefits benefit;
// Methods
public static int NumEmployees
{
get { return numEmployees; }
}
public string EmployeeType
{
get { return employeeType; }
}
public int Dependents
{
get { return dependents;}
set
{
if (value > MAX_DEPENDENTS)
dependents = MAX_DEPENDENTS;
else
if (value < MIN_DEPENDENTS)
dependents = MIN_DEPENDENTS;
else
dependents = value;
}
}
public string FirstName
{
get { return firstName; }
set
{
if (String.IsNullOrEmpty(value))
firstName = DEFAULT_NAME;
else
firstName = value;
}
}
public string LastName
{
get { return lastName; }
set
{
if (String.IsNullOrEmpty(value))
lastName = DEFAULT_NAME;
else
lastName = value;
}
}
public char Gender
{
get { return gender; }
set
{
if(value == 'm' || value == 'M' || value == 'f' || value == 'F')
gender = value;
else
gender = DEFAULT_GENDER;
}
}
public double AnnualSalary
{
get { return annualSalary; }
set
{
if (value < MIN_SALARY)
annualSalary = MIN_SALARY;
else
if (value > MAX_SALARY)
annualSalary = MAX_SALARY;
else
annualSalary = value;
}
}
public Benefits Benefit
{
get { return benefit; }
set
{
if (value != null)
benefit = value;
else
benefit = new Benefits();
}
}
public virtual double CalculateWeeklyPay()
{
return annualSalary / 52;
}
public virtual double CalculateWeeklyPay(double modifiedSalary)
{
AnnualSalary = modifiedSalary;
return annualSalary / 52;
}
public override string ToString()
{
string output;
output = "============ Employee Information ============";
output += " Name: " + firstName + " " + lastName;
output += " Gender: " + gender;
output += " Dependents: " + dependents;
output += " Annual Salary :" + annualSalary.ToString("C2");
output += " Weekly Pay :" + CalculateWeeklyPay().ToString("C2");
output += " Employee Type:" + employeeType;
output += benefit.ToString();
return output;
}
// Constructor
public Employee(string fname, string lname, char gen, int deps, double aSalary, Benefits bene, string empType)
{
FirstName = fname;
LastName = lname;
Gender = gen;
Dependents = deps;
AnnualSalary = aSalary;
employeeType = empType;
Benefit = bene;
numEmployees += 1;
}
public Employee()
{
benefit = new Benefits();
employeeType = "Generic";
numEmployees += 1;
}
public Employee(string employeeType) : this() { }
}
class Salaried : Employee
{
const int MINIMUM_MANAGEMENT_LEVEL = 0;
const int MAXIMUM_MANAGEMENT_LEVEL = 3;
const double BONUS_PERCENT = .10;
int managementLevel;
public int ManagementLevel
{
get { return managementLevel; }
set
{
if (value < MINIMUM_MANAGEMENT_LEVEL)
managementLevel = MINIMUM_MANAGEMENT_LEVEL;
else
if (value > MAXIMUM_MANAGEMENT_LEVEL)
managementLevel = MAXIMUM_MANAGEMENT_LEVEL;
else
managementLevel = value;
}
}
public override double CalculateWeeklyPay()
{
return annualSalary / 52 * (1 + managementLevel*BONUS_PERCENT);
}
public override string ToString()
{
string output;
output = "============ Employee Information ============";
output += " Name: " + firstName + " " + lastName;
output += " Gender: " + gender;
output += " Dependents: " + dependents;
output += " Annual Salary : " + annualSalary.ToString("C2");
output += " Weekly Pay : " + CalculateWeeklyPay().ToString("C2");
output += " Employee Type: " + employeeType;
output += benefit.ToString();
output += " Management Level: " + managementLevel;
return output;
}
public Salaried()
{
employeeType = "Salaried";
}
public Salaried(string fname, string lname, char gen, int deps, double aSalary, Benefits bene,string empType, int manLevel)
: base( fname, lname, gen, deps, aSalary, bene, empType)
{
ManagementLevel = manLevel;
numEmployees += 1;
}
}
class Hourly : Employee
{
const double MIN_WAGE = 10;
const double MAX_WAGE = 75;
const double MIN_HOURS = 0;
const double MAX_HOURS = 50;
const string TEMPORARY = "temporary";
const string PART_TIME = "part time";
const string FULL_TIME = "full time";
const string INVALID_CATEGORY = "invalid category";
double wage;
double hours;
string category;
public double Wage
{
get { return wage; }
set
{
if (value < MIN_WAGE)
wage = MIN_WAGE;
else
if (value > MAX_WAGE)
wage = MAX_WAGE;
else
wage = value;
base.AnnualSalary = CalculateWeeklyPay() * 48;
}
}
public double Hours
{
get { return hours; }
set
{
if (value < MIN_HOURS)
hours = MIN_HOURS;
else
if (value > MAX_HOURS)
hours = MAX_HOURS;
else
hours = value;
base.AnnualSalary = CalculateWeeklyPay() * 48;
}
}
public string Category
{
get { return category; }
set
{
if (value == FULL_TIME || value == PART_TIME || value == TEMPORARY)
category = value;
else
category = INVALID_CATEGORY;
}
}
public override double CalculateWeeklyPay()
{
return wage * hours;
}
public Hourly()
{
employeeType = "Hourly";
}
public override string ToString()
{
string output;
output = "============ Employee Information ============";
output += " Name: " + firstName + " " + lastName;
output += " Gender: " + gender;
output += " Dependents: " + dependents;
output += " Annual Salary : " + annualSalary.ToString("C2");
output += " Weekly Pay : " + CalculateWeeklyPay().ToString("C2");
output += " Employee Type: " + employeeType;
output += benefit.ToString();
output += " Category : " + category;
output += " Hours : " + hours;
output += " Wages : " + wage;
return output;
}
public Hourly(string fname, string lname, char gen, int deps, double aSalary, Benefits bene, string empType, string cat)
: base( fname, lname, gen, deps, aSalary, bene, empType)
{
Category = cat;
numEmployees += 1;
}
}
//Program.cs
class Program
{
static void Main(string[] args)
{
ApplicationUtilities.DisplayApplicationInformation();
Employee[] emps = new Employee[3];
emps[0] = new Employee( "Generic");
emps[1] = new Hourly();
emps[2] = new Salaried();
for (int i = 0; i < emps.Length; i++)
{
ApplicationUtilities.DisplayDivider("Employee Information");
EmployeeInput.CollectEmployeeInformation(emps[i]);
if (emps[i] is Hourly)
{
EmployeeInput.CollectHourlyInformation((Hourly)emps[i]);
}
else if (emps[i] is Salaried)
{
EmployeeInput.CollectSalariedInformation((Salaried)emps[i]);
}
EmployeeOutput.DisplayEmployeeInformation(emps[i]);
ApplicationUtilities.PauseExecution();
}
EmployeeOutput.DisplayNumberObject();
ApplicationUtilities.TerminateApplication();
}
}
//Benefits.cs
class Benefits
{
const string DEFAULT_HEALTH_INSURANCE = "Blue Cross";
const double MIN_LIFE_INSURANCE = 0;
const double MAX_LIFE_INSURANCE = 1000000;
const int MIN_VACATION = 0;
const int MAX_VACATION = 45;
string healthInsuranceCompany = DEFAULT_HEALTH_INSURANCE;
double lifeInsuranceAmount = MIN_LIFE_INSURANCE;
int vacationDays = MIN_VACATION;
// Methods
public string HealthInsuranceCompany
{
get { return healthInsuranceCompany; }
set
{
if (String.IsNullOrEmpty(value))
healthInsuranceCompany = DEFAULT_HEALTH_INSURANCE;
else
healthInsuranceCompany = value;
}
}
public double LifeInsuranceAmount
{
get { return lifeInsuranceAmount; }
set
{
if (value < MIN_LIFE_INSURANCE)
lifeInsuranceAmount = MIN_LIFE_INSURANCE;
else
if (value > MAX_LIFE_INSURANCE)
lifeInsuranceAmount = MAX_LIFE_INSURANCE;
else
lifeInsuranceAmount = value;
}
}
public int VacationDays
{
get { return vacationDays; }
set
{
if (value < MIN_VACATION)
vacationDays = MIN_VACATION;
else
if (value > MAX_VACATION)
vacationDays = MAX_VACATION;
else
vacationDays = value;
}
}
public override string ToString()
{
string output;
output = " ============ Benefit Information ============";
output += " Health Insurance Company: " + healthInsuranceCompany;
output += " Life Insurance Amount: " + lifeInsuranceAmount.ToString("C2");
output += " Vacation Days: "+ vacationDays;
return output;
}
public Benefits()
{
}
public Benefits(string health, double life, int vacation)
{
HealthInsuranceCompany = health;
LifeInsuranceAmount = life;
VacationDays = vacation;
}
}
//InputUtilities.cs
public class InputUtilities
{
public static string GetInput(string inputType)
{
string strInput = String.Empty;
Console.Write("Enter the " + inputType + ": ");
strInput = Console.ReadLine();
return strInput;
}
public static string getStringInputValue(string inputType)
{
string value = String.Empty;
bool valid = false;
string inputString = String.Empty;
do
{
inputString = GetInput(inputType);
if (!String.IsNullOrEmpty(inputString))
{
value = inputString;
valid = true;
}
else
{
value = "Invalid input";
valid = false;
}
if (!valid)
Console.WriteLine("Invalid " + inputType + " try again!");
} while (!valid);
return value;
}
public static int getIntegerInputValue(string inputType)
{
bool valid = false;
int value = 0;
string inputString = String.Empty;
do
{
inputString = GetInput(inputType);
if (!(String.IsNullOrEmpty(inputString)))
{
valid = Int32.TryParse(inputString, out value);
}
if (!valid)
Console.WriteLine("Invalid " + inputType + " try again!");
} while (!valid);
return value;
}
public static double getDoubleInputValue(string inputType)
{
bool valid = false;
double value = 0;
string inputString = String.Empty;
do
{
inputString = GetInput(inputType);
if (!(String.IsNullOrEmpty(inputString)))
{
valid = Double.TryParse(inputString, out value);
}
if (!valid)
Console.WriteLine("Invalid " + inputType + " try again!");
} while (!valid);
return value;
}
public static char getCharInputValue(string inputType)
{
bool valid = false;
char value = 'u';
string inputString = String.Empty;
do
{
inputString = GetInput(inputType);
if (!(String.IsNullOrEmpty(inputString)))
{
valid = Char.TryParse(inputString, out value);
}
if (!valid)
Console.WriteLine("Invalid " + inputType + " try again!");
} while (!valid);
return value;
}
}
//ApplicationUtilities.cs
public class ApplicationUtilities
{
public static void DisplayApplicationInformation()
{
Console.WriteLine("Welcome the Basic Employee Program");
Console.WriteLine("CIS247a, Week 6 Lab");
Console.WriteLine("Name: Angela Groves");
Console.WriteLine("This program accepts user input as a string, then makes the appropriate data conversion and assigns the value to Employee objects");
Console.WriteLine();
}
public static void DisplayDivider(string outputTitle)
{
Console.WriteLine(" ********* " + outputTitle + " ********* ");
}
public static void TerminateApplication()
{
DisplayDivider("Program Termination");
Console.Write("Thank you. Press any key to terminate the program...");
Console.ReadLine();
}
public static void PauseExecution()
{
Console.Write(" Program paused, press any key to continue...");
Console.ReadLine();
Console.WriteLine();
}
}
//EmployeeInput.cs
class EmployeeInput
{
public static void CollectEmployeeInformation(Employee theEmployee)
{
theEmployee.FirstName = InputUtilities.getStringInputValue("First Name");
theEmployee.LastName = InputUtilities.getStringInputValue("Last Name");
theEmployee.Gender = InputUtilities.getCharInputValue("gender");
theEmployee.Dependents = InputUtilities.getIntegerInputValue("Number of Dependents");
if(theEmployee.EmployeeType == "Generic")
theEmployee.AnnualSalary = InputUtilities.getDoubleInputValue("Annual Salary");
theEmployee.Benefit.HealthInsuranceCompany = InputUtilities.getStringInputValue("Insurance Company");
theEmployee.Benefit.LifeInsuranceAmount = InputUtilities.getDoubleInputValue("Insurance Amount");
theEmployee.Benefit.VacationDays = InputUtilities.getIntegerInputValue("Number of Vacation Days");
}
public static
void CollectHourlyInformation(Hourly theEmployee)
{
theEmployee.Wage = InputUtilities.getDoubleInputValue("Wage");
theEmployee.Hours = InputUtilities.getDoubleInputValue("Hours");
theEmployee.Category = InputUtilities.getStringInputValue("Category");
}
public static void CollectSalariedInformation(Salaried theEmployee)
{
theEmployee.ManagementLevel = InputUtilities.getIntegerInputValue("Management Level");
theEmployee.AnnualSalary = InputUtilities.getDoubleInputValue("Annual Salary");
}
}
//EmployeeOutput.cs
class EmployeeOutput
{
public static void DisplayEmployeeInformation(Employee theEmployee)
{
Console.WriteLine(theEmployee.ToString());
}
public static void DisplayNumberObject()
{
Console.WriteLine("Number of Employees created: " + Employee.NumEmployees);
}
}
*******************
The output of your program should resemble the following:
Employee Type Hourly
First Name Mary
Last Name Noia
Dependents 4
Annual Salary $100,000
Weekly Pay $2,080.00
Net Pay $1,705.00
Health Insurance Blue Cross
Life Insurance $175,000
Vacation 24
Hours 40
Wage 52
Category Full Time
Employee Type Salaried
First Name Sue
Last Name Smith
Gender Female
Dependents 2
Annual Salary $100,000.00
Weekly Pay $2,500.00
Net Pay $1,855.00
Health Insurance Blue Cross
Life Insurance $300,000
Vacation 15
Level 3
Image Description
Explanation / Answer
using System; namespace AbstractsANDInterfaces { /// /// Summary description for Emp_Fulltime. /// //Inheriting from the Abstract class public class Emp_Fulltime : Employee { //uses all the properties of the //Abstract class therefore no //properties or fields here! public Emp_Fulltime() { } public override String ID { get { return id; } set { id = value; } } public override String FirstName { get { return fname; } set { fname = value; } } public override String LastName { get { return lname; } set { lname = value; } } //common methods that are //implemented in the abstract class public new String Add() { return base.Add(); } //common methods that are implemented //in the abstract class public new String Delete() { return base.Delete(); } //common methods that are implemented //in the abstract class public new String Search() { return base.Search(); } //common methods that are implemented //in the abstract class public new String Update() { return base.Update(); } //abstract method that is different //from Fulltime and Contractor //therefore I override it here. public override String CalculateWage() { return "Full time employee " + base.fname + " is calculated " + "using the Abstract class..."; } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.