'Java program for getting and setting inputs total run, total match played about cricket players and finding the average run scored using the input

I created this code involving two classes one class player class has all the variables and getter and setter method and the solution class finds the average run using the input of total runs and total match played.

The players will be classified into 3 categories according to their average run. My code is working fine without any error but the average score always shows 0.

Player class

public class Player {
    private int id;
    private int iccRank;
    private int matchPlayed;
    private double averageRun;
    private int totalRun;
    private String name;
}

Solution class

class Solution{
    float a,b,c;

    public static void findAvgOfRun(Player my) {
        float a=my.gettotalRun();
        float b=my.getmatchPlayed();
        float c= a/b;
        my.setaverageRun(c);
    }
    
    public static void main(String[] args) {
        Player my = new Player();
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter Player name: ");
        my.setname(sc.nextLine());
        System.out.print("Enter Player ID: ");
        my.setid(sc.nextInt());
        System.out.print("Enter Player ICC Rank: ");
        my.seticcRank(sc.nextInt());
        System.out.print("Enter number of match played: ");
        my.setmatchPlayed(sc.nextInt());
        System.out.print("Enter Player total run: ");
        my.settotalRun(sc.nextInt());
        sc.close();
        if(my.getaverageRun()<=100 && my.getaverageRun()>=80) {
            System.out.println("He is a grade A player");
        }
        else if(my.getaverageRun()<80 && my.getaverageRun()>=50) {
            System.out.println("He is a grade B player");
        }
        else {
            System.out.println("He is a grade C player");
        }
        
        my.display();
    }


Solution 1:[1]

Please see line where I added comment:

public static void findAvgOfRun(Player my) {
    float a=my.gettotalRun();
    float b=my.getmatchPlayed();
    float c= a/b;
    my.setaverageRun(c);
}

public static void main(String[] args) {
    Player my = new Player();
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter Player name: ");
    my.setname(sc.nextLine());
    System.out.print("Enter Player ID: ");
    my.setid(sc.nextInt());
    System.out.print("Enter Player ICC Rank: ");
    my.seticcRank(sc.nextInt());
    System.out.print("Enter number of match played: ");
    my.setmatchPlayed(sc.nextInt());
    System.out.print("Enter Player total run: ");
    my.settotalRun(sc.nextInt());
    sc.close();
    Solution.findAvgOfRun(my); //In place of solution use your class name in which main method is there.
    if(my.getaverageRun()<=100 && my.getaverageRun()>=80) {
        System.out.println("He is a grade A player");
    }
    else if(my.getaverageRun()<80 && my.getaverageRun()>=50) {
        System.out.println("He is a grade B player");
    }
    else {
        System.out.println("He is a grade C player");
    }
    
    my.display();
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Devidas Kaware