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

Create a class called Employee that contains 3 pieces of information as instance

ID: 3541414 • Letter: C

Question

Create a class called Employee that contains 3 pieces of information as instance variables: first name (datatype string), last name (datatype string), monthly salary.( datatype decimal).
Your class should contain a constructor that initializes the 3 instance variables. It should also contain a property for each instance variable with get and set accessors. The property for salary should verify that the salary is greater than 0. If a negative value is passed in, the set accessor should set the salary to 0.
Create a second class EmployeeTest that creates two employee objects using the constructor that you developed in the Employee class. Display the name and salary for each Employee. Use the set property for salary to give each employee a 10% raise, Display the name and salary for each employee again.

Explanation / Answer

class Employee

{

private string FirstName;

public string First_Name

{

get

{

return FirstName;

}

set

{

FirstName = value;

}

}

private string LastName;

public string Last_Name

{

get

{

return LastName;

}

set

{

LastName = value;

}


}

private int Salary;

public int salary

{

get

{

return Salary;

}

set

{

if(Salary<0)

Salary = 0;

else

Salary = value;

}


}


public Employee(string firstName, string lastName, int slry)

{

FirstName = firstName;

LastName = lastName;

Salary = slry;


}



}


class EmployeeTest

{

public static void Main()

{

Employee employee1 = new Employee("Tom","Micheal",5000);

Employee employee2 = new Employee("Raja","Dutta",6000);

System.Console.WriteLine("First Employee:"+employee1.First_Name+" "+employee1.Last_Name+" "+employee1.salary);

System.Console.WriteLine("Second Employee:"+employee2.First_Name+" "+employee2.Last_Name+" "+employee2.salary);


employee1.salary += employee1.salary/10;

employee2.salary += employee2.salary/10;

System.Console.WriteLine("First Employee:"+employee1.First_Name+" "+employee1.Last_Name+" "+employee1.salary);

System.Console.WriteLine("Second Employee:"+employee2.First_Name+" "+employee2.Last_Name+" "+employee2.salary);


}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote