[Solved] I want to find max and min values in java


In the loop of the getEmployeeDetails() method, you don’t store and update the min wage, the max wage and the employee names that have these wages.
Besides, you should be more specific in the naming. For example, maxWage and minWage are more meaningful than max and min.
So, you should have maxWage, maxWageEmployeeName, minWage and minWageEmployeeName fields in the field declaration of the Wage class.

At each employee inserted in the system, you should update these values by calling a dedicated method:

public void getEmployeeDetails() {

  if (count.equalsIgnoreCase("1")) {
    ....
    updateRanking(sum, employee_name);
  }
}

public void updateRanking(double actualWage, String employee_name){
    if (actualWage > maxWage) {
        maxWage = actualWage;
        maxWageEmployeeName = employee_name;
    }
    else if (actualWage < minWage) {
        minWage = actualWage;
        minWageEmployeeName = employee_name;
    }
}

Besides, your average() method called at the end of your program should only display the result and not performing comparison since you should have updated information about max, min wage and who have these as updateRanking() is called at each insertion of employee wage :

void average() {
    System.out.println("\n\n");
    System.out.println("stastical information for bar chart");
    System.out.println("==================================");           
    System.out.println("Maximum of wage" + maxWage + ",  " + maxWageEmployeeName );      
    System.out.println("Minimum of Wage" + minWage + ",  " + minWageEmployeeName );       
}

2

solved I want to find max and min values in java