What I need help with are the EmployeeInput and EmployeeOutput classes of the Pr
ID: 3638224 • Letter: W
Question
What I need help with are the EmployeeInput and EmployeeOutput classes of the Presentation Tier. I think we are just moving some information from the main program to clean it up a little bit. I'll give you a description of the lab, and then I'll list what I've got so far.i L A B O V E R V I E W
Scenario and Summary
The objective of the lab is to take the UML Class diagram and enhance last week's Employee class by making the following changes:
Create a derived class called Salaried that is derived from Employee.
Create a derived class called Hourly that is derived from Employee.
Create generalized input methods that accept any type of Employee or derived Employee object
Create generalized output methods that accept any type of Employee or derived Employee object
Override the base class CalculatePay method
Override one of the base class CalculateWeeklyPay methods
Deliverables
Due this week:
Capture the Console output window and paste into a Word Document.
Zip the project folder.
Put the zip file and screenshots (word document) in the drop box.
i L A B S T E P S
STEP 1: Understand the UML Diagram
Analyze and understand the object UML diagram, which models the structure of the program.
There are two new Employee derived classes (1) Salaried and (2) Hourly that are derived from the Employee class.
The Employee class contains a new attribute employeeType and a new constructor that accepts as an argument the assigned employee type.
Both the Salaried and the Hourly classes override only the CalculateWeeklyPay method of the Employee class (note, this is the method without any parameters.)
The Salaried class has one attribute "managementLevel" that has possible values from MIN_MANAGEMENT_LEVEL to MAX_MANAGEMENT_LEVEL and a BONUS_PERCENT.
The Salaried class has a default constructor and parameterized constructor that accepts all the general employee information plus the management level.
The Hourly has a wage attribute, which respresents the hourly wage that ranges from MIN_WAGE to MAX_WAGE, a hours attributes, which represents the number of hours worked in a week that ranges from MIN_HOURS to MAX_Hours, and a category attributes that accepts string values.
The Hourly class has a default constructor and parameterized constructor that accepts all the general employee information plus the hours and wage value.
The Presentation Tier contains two new classes (1) The EmployeeInput class and the EmployeeOutput class
The EmployeeInput class contains three static methods (1) CollectEmployeeInformation, which accepts any type of Employee object as a argument; (2) CollectHourlyInformation, which accepts only Hourly objects as an argument, and (3) CollectSalariedInformation, which accepts only Salaried objects as an argument.
The EmployeeOutput class contains two methods (1) DisplayEmployeeInformation, which accepts any Employee type as an argument and (2) DisplayNumberObjects method.
All the access specifers for the Employee attributes are changed to protected and are depicted with the "#" symbol.
STEP 2: Create the Project
You will want to use the Week 4 project as the starting point for the lab. Use the directions from the previous weeks labs to create the project and the folders.
Create a new project named "CIS247_WK4_Lab_LASTNAME". An empty project will then be created.
Delete the default Program.cs file that is created.
Add the Logic Tier, Presentation Tier, and Utilities folders to your proejct
Add the Week 4 project files to the appropraties folders.
Update the program information in the ApplicationUtilities.DisplayApplicationInformation method to reflect your name, current lab, and program description
Note: as an alternative you can open up the Week 4 project and make modifications to the existing project. Remember, there is a copy of your project in the zip file you submitted for grading.
Before attempting this week's steps ensure that the Week 4 project is error free.
STEP 3: Modify the Employee Class
Change the access specifier for all the private attributes to protected.
Add the new attribute employeeType, along with a "read only" property (that is only a "get" method) to access the employee type value.
Add a new constructor that only accepts the type attribute, which is then used to set the employeeType value. Also, this constructor should initialize all the default values. You can call the default constructor using the syntax: public Employee(string employeeType) : this() { }
Modify the parameterized constructor that accepts the employee information to accept the employee type, and then set the employeeType with this value.
Modify the ToString Method to include the employee type.
STEP 4: Create the Salaried Class
Using the UML Diagrams, create the Salaried class, ensuring to specify that the Salary class inherits from the Employee class.
For each of the constructors listed in the Salaried class ensure to invoke the appropriate super class constructor and pass the correct arguments to the super class constructor.
Override the CalculateWeeklyPay method to add a 10 percent bonus to the annualSalary depending on the management level. The bonus percent is a fixed 10 percent, and should be implemented as a constant. However, depending on the management level the actual bonus percentage fluctuates (i.e., actualBonusPercentage = managementLevel * BONUS_PERCENT).
Override the ToString method to add the management level to the employee information.
STEP 5: Create the Hourly Class
Using the UML Diagrams, create the Hourly classes, ensuring to specify that the Hourly class inherits from the Employee class.
For each of the constructors listed in the Hourly class ensure to invoke the appropriate super class constructor and pass the correct arguments to the super class constructor. Notice, that the Hourly employee DOES NOT have an annual salary, which we will then have to calculate (see below).
Create a Category property (get/set) and the valid category types are "temporary", "part time", "full time".
Create a Hours property (get/set) for the hours attributes and validate the input using the constants shown in the UML diagram, but since an Hourly employee does not have a formal annual salary we will need to calculate this each time the hour (and wage) properties are set. Add the following code after the validation code in the hours property: base.AnnualSalary = CalculateWeeklyPay() * 48; (assumes working 48 weeks a year).
Create an Wage property (get/set) for the wage attributes and validate the input using the constants shown in the UML diagram. Add the following code after the validation code in the wage property: base.AnnualSalary = CalculateWeeklyPay() * 48; (assumes working 48 weeks a year)
Override the CalculateWeeklyPay method by multiplying the wages by the number of hours.
Update the ToString method to add the category, hours, and wages to the hourly employee information.
STEP 6: Create the EmployeeInput Class
Create a new class in the Presentation Tier folder called "EmployeeInput"
Create a static void method called CollectEmployeeInformation that has a single Employee parameter. The declaration should look something like the following:
public static void CollectEmployeeInformation(Employee theEmployee)
Write code statements similiar to what you created in the Week 4 project to collect the generic employee information from the user, except instead of using specific employee objects use the "theEmployee" parameters. For example:
In Week 4, you had something like:
employee1.FirstName = InputUtilities.GetStringInputValue("First name");
In the CollectionEmployeeInformation method this can be translated to the following;
theEmployee.FirstName = InputUtilities.GetStringInputValue("First name");
Write statements to collect all the generic employee information, including the Benefits information, as you did in the Week 4 project. However, since not all derived types have a AnnualSalary value, DO NOT collect the annual salary data.
Create a new static void method called CollectEmployeeInformation that accepts an Hourly employee object. Using the InputUtilities methods write statements to collect the wage and hours from the user.
Create a new static void method called CollectSalariedInformation that accepts a Salaried employee object. Using the InputUtilties methods write statements to collect the management level and the annual salary.
STEP 7: Create the Main Program
Create an array of type Employee that will hold three employee objects. Create three new objects, one Employee, one Hourly and one Salaried in positions 0, 1 and 2 of the array respectively. Make sure to use the constructors the accept the employee type and provide appropriate values for the employee type (e.g. "Generic", "Hourly", "Salaried").
Using a FOR loop iterate through the array and collect all the generic employee information, using the EmployeeInput.CollectEmployeeInformation method.
If the current item in the array is an Hourly object, then use the EmployeeInput.CollectHourlyInformation method to collect the hourly information.
If the current item in the array is a Salaried object, then use the EmployeeInput.CollectSalariedInformation method to collect the salaried information.
Use the following if statement to determine the specific type of object:
if (employeeList[i] is Hourly)
EmployeeInput.CollectHourlyInformation((Hourly)employeeList[i]);
else if (employeeList[i] is Salaried)
EmployeeInput.CollectSalariedInformation((Salaried)employeeList[i]);
After the information has been collected display the employee information using the EmployeeOutput.DisplayEmployeeInformation method.
Before terminating the program display the number of employee objects that have been created.
STEP 8: Compile and Test
When done, compile and run your program.
Then debug any errors until your code is error-free.
Check your output to ensure that you have the desired output and modify your code as necessary and rebuild.
The output of your program should resemble the following:
On-screen output display:
Welcome the Employee Hierarchy Program
CIS247, Week 5 Lab
Name: Solution
This program tests an Employee inheritance hierarchy
*********************** Display Employee's Data **********************
Employee Type
GENERIC
First Name
John
Last Name
Student
Gender
Male
Dependents
3
Annual Salary
$20,000.00
Weekly Pay
$384
Health Insurance
Blue Cross
Life Insurance
$20,000
Vacation
21
*********************** Display Employee's Data **********************
Employee Type
Hourly
First Name
Mary
Last Name
Noia
Dependents
4
Annual Salary
$100,000
Weekly Pay
$2,080.00
Health Insurance
Blue Cross
Life Insurance
$175,000
Vacation
24
Hours 40
Wage 52
Category Full Time
*********************** Display Employee's Data **********************
Employee Type
Salaried
First Name
Sue
Last Name
Smith
Gender
Female
Dependents
2
Annual Salary
$100,000.00
Weekly Pay
$2,500.00
Health Insurance
Blue Cross
Life Insurance
$300,000
Vacation
15
Level 3
total Number of Employess in Database: 3
Press the ESC key to close the image description and return to lecture
Image Description
STEP 9: Submit Deliverables
Capture the console output window and paste into a Word document.
Put the zip file and screen shots (Word document) in the Dropbox.
ok...now here is what I've got so far...
// Benefit.cs
class Benefit
{
// data fields
private string healthInsurance;
private double lifeInsurance;
private int vacation;
//default constructor
public Benefit()
{
}
//argumented constructor
public Benefit(string health, double life, int v)
{
healthInsurance = health;
lifeInsurance = life;
vacation = v;
}
//displays the data of the object
public override string ToString()
{
return string.Format(
"Health Insurance: {0} "
"Life Insurance : {1:c} "
"Vacation : {2}", healthInsurance, lifeInsurance, vacation);
}
//sets health insurance
public void SetHealthInsurance(string health)
{
healthInsurance = health;
}
//returns health insurance
public string GetHealthInsurance()
{
return healthInsurance;
}//sets life insurance
public void SetLifeInsurance(double life)
{
lifeInsurance = life;
}//returns life insurance
public double GetLifeInsurance()
{
return lifeInsurance;
}//sets vacation
public void SetVacation(int v)
{
vacation = v;
}//returns vacation
public int GetVacation()
{
return vacation;
}
}
// Employee.cs
class Employee
{
//Private data members
protected string firstName;
protected string lastName;
protected char gender;
protected int dependents;
protected double annualSalary;
//number of employees
private static int numEmployees = 0;
//benift object
protected Benefit benefit;
//Default Constructor
public Employee()
{
firstName = "not given";
lastName = "not given";
gender = 'U';
dependents = 0;
annualSalary = 20000;
//updates number of employees
numEmployees ;
benefit = new Benefit("not given", 0, 0);
}//End of Default Constructor
//Argumented Constructor
public Employee(string first, string last, char gen, int dep, double salary, Benefit benefit)
{
firstName = first;
lastName = last;
gender = gen;
dependents = dep;
annualSalary = salary;
//updates number of employees
numEmployees ;
this.benefit = new Benefit(benefit.GetHealthInsurance(), benefit.GetLifeInsurance(), benefit.GetVacation());
}//End of Argumented Constructor
//Calculates weekly pay
public virtual double CalculatePay()
{
return annualSalary / 52;
}//End of CalculatePay method
//Displays all the data of the employee
public override string ToString()
{
return string.Format(
"Employee Type : {0} "
"First Name : {1} "
"Last Name : {2} "
"Gender : {3} "
"Dependents : {4} "
"Annual Salary : {5:c} "
"Weekly Pay : {6:c} {7}",
"GENERIC", FirstName, LastName, (Gender == 'M') ? "Male" : "Female", Dependents, AnnualSalary, CalculatePay(), benefit.ToString());
}//End of DisplayEmployee method
//Public properties
//Property for first name of the employee
public string FirstName
{
set
{
firstName = value;
}
get
{
return firstName;
}
}// End of FirstName method
//Property for last name of the employee
public string LastName
{
set
{
lastName = value;
}
get
{
return lastName;
}
}//End of LastName method
//Gender of the employee
public char Gender
{
set
{
gender = value;
}
get
{
return gender;
}
}//End of Gender method
//The dependets
public int Dependents
{
set
{
dependents = value;
}
get
{
return dependents;
}
}//End of the Dependents method
//Annual salary
public double AnnualSalary
{
set
{
annualSalary = value;
}
get
{
return annualSalary;
}
}//End of AnnualSalary method
//Additional setter method for dependents
public void SetDependents(int dep)
{
dependents = dep;
}//End of SetDependents method
//Additional setter method for annual salary
public void SetAnnualSalary(double salary)
{
annualSalary = salary;
} //End of SetAnnualSalary method
//returns number of employees created
public static int GetNumberOfEmployees()
{
return numEmployees;
}//End of GetNumberOfEmployees method
//overloaded method of setDependents with string parameter
public void SetDependents(string dep)
{
dependents = Convert.ToInt32(dep);
}//End of SetDependents method
//overloaded method of setAnnualSalary with string parameter
public void SetAnnualSalary(string salary)
{
annualSalary = Convert.ToDouble(salary);
}//End of SetAnnualSalary method
}
// Salaried.cs
class Salaried : Employee
{
// constant values for minmum and maximum management levels
private const int MIN_MANAGEMENT_LEVEL = 0;
private const int MAX_MANAGEMENT_LEVEL = 3;
// bonus percentage
private const double BONUS_PERCENT = 10.0;
// employee management level
private int managementLevel;
// noargument constructor
public Salaried()
: base()
{
managementLevel = MIN_MANAGEMENT_LEVEL;
}
// 7-ArgumentException constructor
public Salaried(string first, string last, char gen, int dep, double salary, Benefit benefit, int manLevel)
: base(first, last, gen, dep, salary, benefit)
{
setManagementLevel(manLevel);
}
// 2-argument constructor
public Salaried(double salary, int manLevel)
: base()
{
AnnualSalary = salary;
setManagementLevel(manLevel);
}
// helper method to set management level
public void setManagementLevel(int manLevel)
{
if (manLevel >= MIN_MANAGEMENT_LEVEL && manLevel <= MAX_MANAGEMENT_LEVEL)
managementLevel = manLevel;
else
managementLevel = MIN_MANAGEMENT_LEVEL;
}
// overrides the base class method calculatePay
public override double CalculatePay()
{
double weekPay = AnnualSalary / 52;
return weekPay weekPay * (managementLevel * BONUS_PERCENT / 100);
}
//overrides the base class ToString to display data of the object
public override string ToString()
{
return string.Format(
"Employee Type : {0} "
"First Name : {1} "
"Last Name : {2} "
"Gender : {3} "
"Dependents : {4} "
"Management Lvl. : {5} "
"Annual Salary : {6:c} "
"Weekly Pay : {7:c} {8}",
GetType().Name.ToUpper(), FirstName, LastName, (Gender == 'M') ? "Male" : "Female", Dependents, managementLevel, AnnualSalary, CalculatePay(), benefit.ToString());
}
}
// Hourly.cs
class Hourly : Employee
{
//constant values for minimum, maximum wage and hours
private const double MIN_WAGE = 10;
private const double MAX_WAGE = 75;
private const double MIN_HOURS = 0;
private const double MAX_HOURS = 50;
private double wage; // wage of employee
private double hours; // hours worked
private string category; // category
// noargument constructor
public Hourly()
: base()
{
wage = MIN_WAGE;
hours = MIN_HOURS;
category = "Not Given";
}
// 3-argument constructor
public Hourly(double wage, double hours, string category)
: base()
{
setWage(wage);
setHours(hours);
setCategory(category);
}
// 8-argument cinstructor
public Hourly(string first, string last, char gen, int dep, double wage, double hours, Benefit ben, string category)
: base(first, last, gen, dep, wage * 1300, ben)
{
setWage(wage);
setHours(hours);
setCategory(category);
}
// helper functions to set wage, hours and category
public void setWage(double wage)
{
if (wage >= MIN_WAGE && wage <= MAX_WAGE)
this.wage = wage;
else
this.wage = MIN_WAGE;
}
//sets hours
public void setHours(double hours)
{
if (hours >= MIN_HOURS && hours <= MAX_HOURS)
this.hours = hours;
else
this.hours = MIN_HOURS;
}
//sets category
public void setCategory(string category)
{
if (category == "temporary" || category == "part time" || category == "full time")
this.category = category;
else
this.category = "temporary";
}
// overrides the base class method calculatePay
public override double CalculatePay()
{
return wage * hours;
}
//overrides the base class ToString to display data of the object
public override string ToString()
{
return string.Format(
"Employee Type : {0} "
"First Name : {1} "
"Last Name : {2} "
"Gender : {3} "
"Dependents : {4} "
"Category : {5} "
"Wage : {6:c} "
"Hours : {7} "
"Weekly Pay : {8:c} "
"Annual Salary : {9:c} {10}",
GetType().Name.ToUpper(), FirstName, LastName, (Gender == 'M') ? "Male" : "Female", Dependents, category, wage, hours, CalculatePay(), AnnualSalary, benefit.ToString());
}
}
// Program.cs (main program)
class Program
{
static void Main(string[] args)
{
Console.WriteLine(" This program tests an Employee inheritance hierarchy ");
// arrsy to hold Employee type objects
Employee[] emp = new Employee[3];
// initializing 3 values of array with 3 three types of classes
// Employee class object
emp[0] = new Employee("Joe", "Doe", 'M', 1, 10000.0, new Benefit("Partial", 1000, 2));
// Salaried Employee
emp[1] = new Salaried("Zoe", "Likoudis", 'M', 3, 20000.0, new Benefit("Full", 2000, 4), 1);
// Hourly Employee
emp[2] = new Hourly("Kate", "Perry", 'F', 0, 75, 25, new Benefit("Partial", 3000, 8), "part time");
// displaying their data to the console
for (int i = 0; i < emp.Length; i )
{
Console.WriteLine(" ***************** Display Employee's Data ***************** ");
Console.WriteLine(emp[i].ToString());
}
//displaying number of emps
Console.WriteLine(" Total number of Employees in Database : {0} ", Employee.GetNumberOfEmployees());
}
}
Explanation / Answer
class Entity { private String name; public Entity(String name) { this.name = name; } public String getName() { return name; } public void move() { System.out.println("I am " + name + ". Here I go!"); } } class Playable extends Entity { public Playable(String name) { super(name); } public void move() { System.out.println("I am " + getName() + ". Here we go!"); } } class Ogre extends Entity { public Ogre(String name) { super(name); } } class Troll extends Entity { public Troll(String name) { super(name); } } class Princess extends Playable { public Princess(String name) { super(name); } public void move() { System.out.println("I am " + getName() + ". Watch as I and my court move!"); } } class Wizard extends Playable { public Wizard(String name) { super(name); } public void move() { System.out.println("I am " + getName() + ". Watch me translocate!"); } } public class EntityTest { public static void main(String[] args) { String[] names = { "Glogg", "Blort", "Gruff", "Gwendolyne", "Snow White", "Diana", "Merlin", "Houdini", "Charles", "George" }; for (int i = 0; i < 10; i++) { int r = (int) (Math.random() * 4); Entity e = null; switch (r) { case 0: e = new Ogre(names[i]); break; case 1: e = new Troll(names[i]); break; case 2: e = new Wizard(names[i]); break; case 3: e = new Princess(names[i]); break; } e.move(); } } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.