fork download
  1. import java.util.*;
  2.  
  3. class Player{
  4. int id;
  5. int matchesPlayed;
  6. int totalRuns;
  7. String name;
  8. String team;
  9.  
  10. Player(int id, int matchesPlayed, int totalRuns, String name, String team){
  11. this.id = id;
  12. this.matchesPlayed = matchesPlayed;
  13. this.totalRuns = totalRuns;
  14. this.name = name;
  15. this.team = team;
  16. }
  17. }
  18. class Ideone{
  19.  
  20. public static int fATROP(Player[] players){
  21. int sum = 0;
  22.  
  23. for(Player p : players){
  24. sum += p.totalRuns;
  25. }
  26.  
  27. if(sum == 0){
  28. return 0;
  29. }
  30. return (sum / players.length);
  31.  
  32. }
  33. public static ArrayList<Player> fPWMMP(Player[] players){
  34.  
  35. ArrayList<Player> ls = new ArrayList<>();
  36.  
  37. for(Player p : players){
  38. ls.add(p);
  39. }
  40.  
  41. if(ls.size() == 0){
  42. return null;
  43. }
  44.  
  45. Collections.sort(ls, (a,b) -> Integer.compare(a.matchesPlayed, b.matchesPlayed));
  46.  
  47. return ls ;
  48. }
  49.  
  50. public static void main(String[] args){
  51. Scanner sc = new Scanner(System.in);
  52. Integer n = sc.nextInt(); sc.nextLine();
  53.  
  54. Player[] players = new Player[n];
  55.  
  56. for(int i = 0; i < n; i++){
  57. Integer a = sc.nextInt(); sc.nextLine();
  58. Integer b = sc.nextInt(); sc.nextLine();
  59. Integer c = sc.nextInt(); sc.nextLine();
  60. String d = sc.nextLine();
  61. String e = sc.nextLine();
  62. players[i] = new Player(a, b, c, d, e);
  63. }
  64.  
  65. int avg = fATROP(players);
  66.  
  67. if(avg == 0){
  68. System.out.println();
  69. }else{
  70. System.out.println("Avg of total Players is: " + avg);
  71. }
  72. ArrayList<Player> list2 = fPWMMP(players);
  73.  
  74. if(list2 == null){
  75. System.out.print("No Player found with mentioned attribute");
  76. }else{
  77. Player p = list2.get(0);
  78.  
  79. System.out.println("id:" + p.id);
  80. System.out.println("matchPlayed:" + p.matchesPlayed);
  81. System.out.println("totalRuns:" + p.totalRuns);
  82. System.out.println("name:" + p.name);
  83.  
  84. }
  85. }
  86. }
Success #stdin #stdout 0.14s 60856KB
stdin
3
201
10
400
A
Team1
202
10
600
B
Team2
203
10
800
C
Team3
stdout
Avg of total Players is: 600
id:201
matchPlayed:10
totalRuns:400
name:A