Methods using C#, How do you GetBi-WeeklySalary(), which returns the salary for
ID: 3588851 • Letter: M
Question
Methods using C#, How do you GetBi-WeeklySalary(), which returns the salary for ½ month of work. This method is an abstract. Also how do you GetAccruedVacation(), which returns the number of vacation time earned by the employee. Vacation accrued follows the following rule: Employee earns 1 week of vacation a year for the first 3 years of service, Then earns an extra day of vacation every year after that for the next 7 years. Vacation time will not change thereafter (this method should not be abstract).
Mwthod GetSeniority(),Which should return the employee years of service (from hire time to now) this method should not be abstract.
Explanation / Answer
using System;
public interface Salary
{
double GetBiWeeklySalary(double salary);
}
public class TestSalary : Salary
{
public int GetAccruedVacation(int serviceYear)
{
if(serviceYear <=3)
return 7;
else
return (7 + (serviceYear-3));
}
public int GetSeniority(int serviceYear)
{
return serviceYear;
}
public static void Main()
{
TestSalary ts = new TestSalary();
Console.WriteLine("Enter the monthly salary of the employee : ");
double salary = Convert.ToDouble(Console.ReadLine());
Console.WriteLine(" His bi-weekly salary : $"+ts.GetBiWeeklySalary(salary));
Console.WriteLine(" Enter the years of service : ");
int serviceYear = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(" His accrued vacation : "+ts.GetAccruedVacation(serviceYear));
Console.WriteLine(" His seniority in years : "+ ts.GetSeniority(serviceYear));
}
public double GetBiWeeklySalary(double salary)
{
return salary/2;
}
}
Output: