I'm working on a windows form application which purpose is to calculate and display Salary statistics stored on a textfile.
I'm having a problem with one task right now: Calculate which profession who has the highest average current salary.
I have stored every salary statistics as SalaryInformation objects. I'll show you how the SalaryInformation class looks like:
public sealed class SalaryInformation
{
private string profession;
private int yearOfEmployment;
private decimal startSalary;
private decimal currentSalary;
public string Profession
{
get { return profession; }
set { profession = value; }
}
public int YearOfEmployment
{
get { return yearOfEmployment; }
set { yearOfEmployment = value; }
}
public decimal StartSalary
{
get { return startSalary; }
set { startSalary = value; }
}
public decimal CurrentSalary
{
get { return currentSalary; }
set { currentSalary = value; }
}
public SalaryInformation()
{ }
public SalaryInformation(string p, int yoe, decimal startS, decimal currentS)
{
profession = p;
yearOfEmployment = yoe;
startSalary = startS;
currentSalary = currentS;
}
What I want to do is to return a single string. The profession property of a SalaryInformation object which is associated with the highest average currentSalary. Bear in mind that there a several SalaryInformation objects who have common profession value (For example, three SalaryInformation objects have the value "doctor" on the property profession).
I started with this method, and I got stuck here:
public string GetHighestPaidProfession()
{
string highestPaidProfession = "";
//Gets all the salaryInformation objects and stores them in a list
List<SalaryInformation> allSalaries = new List<SalaryInformation>();
allSalaries = data.GetSalaryInformation();
//Right here I don't know how to do the rest from here.
//I realize that I have to calculate the average currentsalary from every
//SalaryInformation I got in the list allSalaries. But then I have to
//to get the actual profession which has the highest average currentsalary
//among them. It's right there I get stuck.
return highestPaidProfession;
}
If you need more code and details, just let me know and I'll add it to this thread.