I need to find the company with the highest earnings.
So far I am able to pull out the highest total Earnings from the loop but have no idea how to get the company name that ties with this highest earnings.
while( count <= noOfComp)
{
System.out.print("Enter Company: ");
companyName = kb.nextLine();
System.out.print("Number of hires: ");
noOfHires = kb.nextInt();
kb.nextLine();
//calculations
totalEarnings = noOfHires * 2500 + 10000;
System.out.println("Total Earnings of company is :" + totalEarnings);
totalEarned = "" + totalEarnings;
if(totalEarnings > large ) //If statement for largest number
{
large = totalEarnings;
}
allTotalEarnings += totalEarnings;
count++;
}
You can assign the highest earning company name and its earnings in variables after the calculation by comparing with previous highest with calculated one.