computer science

I need to see if someone can help me with a c# programming problem Create a class called employees that includes three pieces of information as either instance variables or automatic properties - a first name(type string), a last name (type string) and a monthly salary (decimal). Yor class should hace a constructor that initializes the three values. Provide a pproperty with get and set accessor for any instance variable. Of the monthly salary is negative, the set accessor should leave the instance variable unchanged. Write a test application named EmployeeTest that demonstrates class Employee's capabilities. Create two Employee objects and display each object's yearly salary. Then give each Employee a 10% raise and display each Employee's yearly salary again.

Answers

// Employee class public class Employee { // Instance variables public string FirstName { get; set; } public string LastName { get; set; } private decimal monthlySalary; // Constructor public Employee(string firstName, string lastName, decimal monthlySalary) { FirstName = firstName; LastName = lastName; if (monthlySalary >= 0) this.monthlySalary = monthlySalary; } // Property for monthly salary public decimal MonthlySalary { get { return monthlySalary; } set { if (value >= 0) monthlySalary = value; } } } // Main test application class EmployeeTest { static void Main() { Employee e1 = new Employee("John", "Smith", 3000); Employee e2 = new Employee("Sara", "Brown", 4000); // Display each employee's yearly salary decimal e1Yearly = e1.Monthly

Answered by Denise

We have mentors from

Contact support