In C#, I have 6 teaching positions. I have to keep my salary expenses below $250
ID: 3703755 • Letter: I
Question
In C#,
I have 6 teaching positions. I have to keep my salary expenses below $250,000 and each position carries insurance and tax costs equal to 25% of their salary.
Create an application that allows me to enter the Years of Experience for 6 teacher positions. Based on those years of experience, look up the minimum salary, total the salaries for all 6 positions. Calculate the 25% tax and insurance expense based on the salaries, and display the total of the tax and insurance expenses to the user. Finally display the total salary, tax, and insurance expenses to the user.
If the total is more than $250,000 then allow the user to start over.
Minimum Salary
Years of Experience
31600
0
31975
1
32350
2
32725
3
33100
4
33500
5
33900
6
This project should include a CalculateTotalSalaries method which returns the total. The salaries should be passed to this method as a parameter.
This project should also include a CalculateTaxAndInsurance method which returns the total tax and insurance expenses based on an array of salaries. The array of salaries should be passed to this method as a parameter.
Minimum Salary
Years of Experience
31600
0
31975
1
32350
2
32725
3
33100
4
33500
5
33900
6
Explanation / Answer
using System;
namespace Rextester
{
public class Program
{
//calculate salary based on experience provided
static int findSalary(int no)
{
int salary=0;
switch(no){
case 0:salary=31600;
break;
case 1:salary=31975;
break;
case 2:salary=32350;
break;
case 3:salary=32725;
break;
case 4:salary=33100;
break;
case 5:salary=33500;
break;
case 6:salary=33900;
break;
}
return salary;
}
//calculate total salaries
static int CalculateTotalSalaries(int[] salaries)
{
int total=0;
for(int i=0;i<salaries.Length;i++)
total+=salaries[i];
return total;
}
//calculate totalTaxAndInsurance expenses
static double CalculateTaxAndInsurance(int[] salaries)
{
double totalTaxAndInsurance=0.0;
for(int i=0;i<salaries.Length;i++)
totalTaxAndInsurance+=salaries[i]*0.25;
return totalTaxAndInsurance;
}
public static void Main(string[] args)
{
int total=0;
int[] salaries = new int[6];
do{
if(total>250000)
{
Console.WriteLine("Total expenses exceeds 250000...Choose again");
total=0;
}
Console.WriteLine("Enter the years of experience [0,6] for 6 teacher positions ");
for(int i=0;i<6;i++)
{
int exp;
try{
exp=Convert.ToInt32(Console.ReadLine());
}
catch(Exception)
{
//If user inputs a string instead of number
Console.WriteLine("Invalid experience");
return;
}
//If exp more than 6
if(exp>6 || exp <0)
{
Console.WriteLine("Invalid experience");
return;
}
salaries[i]= findSalary(exp);
}
//calculate total salaries
total=CalculateTotalSalaries(salaries);
Console.WriteLine("Total Salaries = {0}",total);
//calculate total tax
int insExp=(int)CalculateTaxAndInsurance(salaries);
//Do a total of both
total+=insExp;
Console.WriteLine("Total TaxAndInsurance = {0}",CalculateTaxAndInsurance(salaries));
}while(total>250000);//if more , do a start over
}
}
}