Create a class called Employee that includes three pieces of information as eith
ID: 3584061 • Letter: C
Question
Create a class called Employee that includes three pieces of information as either instance variables or automatic properties - a firstname (type string), a last name (type string) and a monthly salary (decimal) Your class should have a constructor that initializes the three values. Provide a property with a get and set accessor for any instance variable. If the monthly salary is negative, the set accessor should leave the instance variable unchanged. Write a test application name EmployeeTest that demonstrate class Employees capabilities. Create two Employee objects and display each objects yearly salary. Then give each employee a 10% raise and display each employees yearly salary again.Explanation / Answer
//C# code onlye
//Rate me first then only I can get points
public class Employee {
private string firstName;
private string lastName;
private int monthlySalary;
public Employee() {
firstName ="unknown";
lastName ="unknown";
monthlySalary = 0;
}
///----------------------code by Ravi-----------------------------
public Employee(string fN, string lN, int mS) {
firstName = fN;
lastName = lN;
monthlySalary = mS;
}
public string getFirstName() {
return firstName;
}
public void setFirstName(String fN) {
firstName = fN;
}
public string getLastName() {
return lastName;
}
///----------------------code by Ravi-----------------------------
public void setLastName(String lN) {
lastName = lN;
}
public int getMonthlySalary() {
return monthlySalary;
}
///----------------------code by Ravi-----------------------------
public void setMonthlySalary(int mS) {
if(monthlySalary > 0)
monthlySalary = mS;
}
public int getYearlySalary() {
return 12 * this.monthlySalary;
}
}
///----------------------code by Ravi-----------------------------
class EmployeeTest {
static void Main() {
Employee emp1 = new Employee("Emp", "1", 10000);
Employee emp2 = new Employee ("Emp", "1", 20000);
///----------------------code by Ravi-----------------------------
//increase salary of each by 10%
emp1.setMonthlySalary(emp1.getMonthlySalary() * (1 + 10/100));
emp2.setMonthlySalary(emp2.getMonthlySalary() * (1 + 10/100));
}
}
///----------------------code by Ravi-----------------------------
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.