(C# Programming) Create a class called Employee that includes three pieces of information as instance variables — a first name (type string), a last name (type string) and a monthly salary (double). Your class should have two constructors, one default and one that initializes the three values. Provide the properties with a get and set accessor for all instance variables. If 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.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Employee
{
public string first_name, last_name;
public double salary;
public Employee()
{
first_name = "";
last_name = "";
salary = 0.0;
}
public Employee(string first_name, string last_name, double salary)
{
this.first_name = first_name;
this.last_name = last_name;
this.salary = salary;
}
public string First_Name
{
get
{
return first_name;
}
set
{
this.first_name = value;
}
}
public string Lats_Name
{
get
{
return last_name;
}
set
{
this.last_name = value;
}
}
public double Salary
{
get
{
return salary;
}
set
{
this.salary = value;
}
}
}
}
namespace ConsoleApplication2
{
class EmployeeTest
{
static void Main()
{
Employee e1 = new Employee("sherlock", "holmes", 1000);
Employee e2 = new Employee("shane", "watson", 500);
System.Console.WriteLine("Salary of First Employee is :");
System.Console.WriteLine(e1.Salary * 12);
System.Console.WriteLine("Salary of Second Employee is :");
System.Console.WriteLine(e2.Salary * 12);
System.Console.WriteLine("Salary of First Employee after Increment by 10% is :");
System.Console.WriteLine(e1.Salary * 12 * (1 + 0.1));
System.Console.WriteLine("Salary of Second Employee after Increment by 10% is :");
System.Console.WriteLine(e2.Salary * 12 * (1 + 0.1));
System.Console.ReadLine();
}
}
}
Explain each step for me pls, and fix anything that might be incorrect.
(C# Programming) Create a class called Employee that includes three pieces of information as instance variables — a firs
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am