C# Create a “Worker” classes that are derived from Employee class. In Worker cla
ID: 3931348 • Letter: C
Question
C#
Create a “Worker” classes that are derived from Employee class. In Worker class, it has one field, yearWorked. It includes constructor(s) and properties. It also includes two functions: first, calcYearWorked function, it takes one parameter (currentyear) and calculates the number of year the worker has been working (current year–yearStartedWked) and save it in the yearWorked variable. Second, the calcCurSalary function that calculate the current year salary by overriding the base class function using initial salary with 3% yearly increment.
(Employee class has been previously created)
Employee.cs
public class Employee
{
private string firstName;
private string lastName;
private int workID;
private int yearStartedWked;
private double initSalary;
private readonly double curSalary;
public Employee(string f, string l, int w, int y, double i, double c){
firstName = f;
lastName = l;
workID = w;
yearStartedWked = y;
initSalary = i;
curSalary = c;
}
public void calcCurSalary(){
initSalary = curSalary;
}
}
Explanation / Answer
public class Worker:Employee
{
Worker()
{
public int yearWorked;
}
public void calcYearWorked(int currentyear)
{
yearWorked=currentyear-yearStartedWked;
}
public void calCurSalary()
{
curSalary=initSalary*0.03;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.