I would also encourage you to try the challenge as practice even if you do not choose to submit it.
You will write a console program that will meet the following requirements:
Create a console program where you will implement coding constructs classes and variables that are needed for this program.
Create an employee class.
Declare all class variables as private. Declare class variables for salary, a string paygrade, and a constant double variable for base salary, string variables for employee last name, employee first name and an integer variable for employee job level.
Create and implement properties (accessors) to get/set the values for employee last name, employee first name and employee level class variables. These should NOT be automatic properties; they will be used wherever these three class variables are referenced in the class.
Create an employee class constructor that will receive the string last name, string first name and integer level when the class object is instantiated and use the accessors to assign the passed values.
Create a public class method to calculate the salary, a public class method to set the paygrade and a public class method to display the output (as shown in the output example).
The set paygrade class method will check the employee level and assign the string value of “Entry Level” if the level passed in is 1, “Mid-Level” if the level passed in is 2 and “Senior Level” if the level passed in is 3.
The calculate salary class method will compute salary based on the following:
If the level is 1 and paygrade is entry level then salary is the base salary times 1.
If the level is 2 and paygrade is mid level then salary is the base salary times 3.
If the level is 3 and paygrade is senior level then salary is the base salary times 5.
The public display class method will display the information as shown in the output example shown below.
In Main you will:
Instantiate three (3) employee object passing the following to the constructor
last name, first name and level number 1, 2 or 3 for each object respectively.
For each instantiated object you will call the set paygrade, calculate salary and display employee class methods following instantiation of each object.
You should format your output to look like the following:
Employee Jack Spratt is a Entry Level with a salary of $35,000.00
Employee Jane Doe is a Mid-Level with a salary of $105,000.00
Employee John Smith is a Senior Level with a salary of $175,000.00
Press any key to continue . . .
This will require some analysis of the problem before coding is accomplished.
Submit this challenge to the link provided below.
LANGAUGE C #
Expert Answer
Solution===================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Salary
{
class Employee
{
private Double salary;
private string paygrade;
private readonly double baseSalary;
private string firstName;
private string lastName;
private int jobLevel;
public Employee(string lname, string fname, int jobLvl)
{
setFirstName(fname);
setLastName(lname);
setJobLevel(jobLvl);
baseSalary = 35000;
}
public void setPaygrade()
{
if (jobLevel == 1)
{
paygrade = “Entry Level”;
}else if(jobLevel == 2)
{
paygrade = “Mid-Level”;
}
else if (jobLevel == 3)
{
paygrade = “Senior Level”;
}
}
public void calculateSalary()
{
if (jobLevel == 1 && paygrade.Equals(“Entry Level”))
{
salary = baseSalary;
}
else if (jobLevel == 2 && paygrade.Equals(“Mid-Level”))
{
salary = baseSalary*3;
}
else if (jobLevel == 3 && paygrade.Equals(“Senior Level”))
{
salary = baseSalary * 5;
}
}
public void display()
{
Console.WriteLine(“Employee “+ firstName+” “+lastName+” is a “+ paygrade + ” with a salary of $”+ String.Format(“{0:n}”, salary));
}
public string getFirstName()
{
return firstName;
}
public string getLastName()
{
return lastName;
}
public int getJobLevel()
{
return jobLevel;
}
public void setJobLevel(int jl)
{
jobLevel = jl;
}
public void setFirstName(string fname)
{
firstName = fname;
}
public void setLastName(string lname)
{
lastName = lname;
}
}
class Program
{
static void Main(string[] args)
{
Employee e1 = new Employee(“Spratt”, “Jack”, 1);
Employee e2 = new Employee(“Doe”, “Jane”, 2);
Employee e3 = new Employee(“Smith”, “John”, 3);
e1.setPaygrade();
e1.calculateSalary();
e1.display();
e2.setPaygrade();
e2.calculateSalary();
e2.display();
e3.setPaygrade();
e3.calculateSalary();
e3.display();
Console.WriteLine(“nnPress any key to Continue…”);
Console.Read();
}
}
}
Output==================================================