In my java program, there are objects of a class called salesperson.
These objects have an attribute called sales and an attribute called name.
I want to compare the sales values to find the largest value and then print out the name of the object that has the highest sale value.
How I did it was
double highSales;
String highSalesString;
highSales=first.getJanSales();
highSalesString=first.getSName() +" "+ first.getTitle();
if (second.getJanSales()>highSales)
{
highSales=second.getJanSales();
highSalesString=second.getSName() +" "+ second.getTitle();
}
if (third.getJanSales()>highSales)
{
highSales=third.getJanSales();
highSalesString=third.getSName() +" "+ third.getTitle();
}
I feel like there's a much simpler way to achieve this.