Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a base Employee class with instance variables and properties: FirstName &

ID: 3564894 • Letter: C

Question

Create a base Employee class with instance variables and properties: FirstName & LastName. The constructor for Employee should accept values for firstname, lastname and socialSecurityNumber and initial the values. Employee should have a toString method to output the values for each employee.

Create a derived class for an employee type Pieceworker. A pieceworker is paid a fee for each piece completed, i.e., # pieces * fee per piece. Class Pieceworker should add private instance variables fee and pieces. Pieceworker should inherit from Employee; adding in an earnings method to calculate earnings. Create a constructor to initialize firstname, lastname, socialSecurityNumber, fee and pieces. Override the toString method to output all variables.

Create a third class to create objects of Pieceworker, then calculate earnings; output all values including earnings.

Step by step instructions so I can understand would be greatly appreciated!

THANKS!!

Explanation / Answer


class Employee
{
public string FirstName { get; set; } //public property
public string LastName { get; set; }
protected string SocialSecurityNumber; //private to called and visible to derived class
public Employee(string firstname,string lastname,string socialsecuritynumber) //constructer with 3 parameters
{

//set passed parameter values in instance variable values

this.FirstName = firstname;
this.LastName = lastname;
this.SocialSecurityNumber = socialsecuritynumber;
}
public string ToString()
{

//return the concatenated string of details
return FirstName + " " + LastName + " " + SocialSecurityNumber;
}
}

class PieceWorker:Employee // inherit employee
{
int pieces;
double fee;
public PieceWorker(string firstname,string lastname,string number,double fee,int pieces):base(firstname,lastname,number) /*constructor with 5 parameters and with 3 parameters call constructor of base class and use 2 parameters for this class*/
{
this.pieces = pieces;
this.fee = fee;

}
public double Earning()
{
return pieces * fee;
}
public string ToString()
{
return "FirstName: " + FirstName + " ,LastName: " + LastName + " ,Number: " + SocialSecurityNumber + " ,Pieces: " + pieces + " ,Fee: " + fee;
}
}

class Test

{

static void Main(String[] args)
{
Console.WriteLine("Object 1");
PieceWorker obj = new PieceWorker("jack", "road", "6663995", 2.5, 1500);
Console.WriteLine(obj.ToString());
Console.WriteLine("Earning: " + obj.Earning());
Console.WriteLine(" Object 2");
obj = new PieceWorker("Randy", "Pilch", "55599322", 5, 100);
Console.WriteLine(obj.ToString());
Console.WriteLine("Earning: " + obj.Earning());
Console.WriteLine(" Object 3");
Employee obj1 = new Employee("Randy", "Pilch", "55599322");
Console.WriteLine(obj1.ToString());

}