Advertisement
Guest User

MVP

a guest
Nov 14th, 2019
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. class player
  2. {
  3. private String Name;
  4. private String Team;
  5. private int Points;
  6.  
  7. player (String name, String team)
  8. {
  9. this.Name = name;
  10. this.Team = team;
  11. this.Points = (int)(Math.random()*100) % 50;
  12. }
  13.  
  14. public String getName ()
  15. {
  16. return Name;
  17. }
  18.  
  19. public void setName (String n)
  20. {
  21. Name = n;
  22. }
  23.  
  24. public int getPoints ()
  25. {
  26. return Points;
  27. }
  28.  
  29. public void setPoints (int p)
  30. {
  31. Points = p;
  32. }
  33.  
  34. public static player MVP(player[] plarray)
  35. {
  36. int maxpoints = 0, index = -1;
  37. for(int i = 0; i < plarray.length; i++){
  38. if(maxpoints < plarray[i].getPoints()){
  39. maxpoints = plarray[i].getPoints();
  40. index = i;
  41. }
  42.  
  43. }
  44. player returner = plarray[index];
  45. return returner;
  46. }
  47.  
  48. }
  49.  
  50.  
  51. public class practice {
  52.  
  53. public static void main(String[] args)
  54. {
  55. player LA [] = new player [5];
  56. LA[0] = new player ("player_1", "LA");
  57. LA[1] = new player ("player_2", "LA");
  58. LA[2] = new player ("player_3", "LA");
  59. LA[3] = new player ("player_4", "LA");
  60. LA[4] = new player ("player_5", "LA");
  61.  
  62. player MH[] = new player [5];
  63. MH[0] = new player ("player_1", "MH");
  64. MH[1] = new player ("player_2", "MH");
  65. MH[2] = new player ("player_3", "MH");
  66. MH[3] = new player ("player_4", "MH");
  67. MH[4] = new player ("player_5", "MH");
  68.  
  69. int pointsLA = 0;
  70. int pointsMH = 0;
  71.  
  72.  
  73.  
  74. for (int i=0; i<=4; i++)
  75. {
  76. System.out.println("Player from team LA: " +LA[i].getName() + " his points: " +LA[i].getPoints());
  77. }
  78. System.out.println();
  79. for (int i=0; i<=4; i++)
  80. {
  81. System.out.println("Player from team MH: " +MH[i].getName() + " his points: " +MH[i].getPoints());
  82. }
  83.  
  84. for (int i = 0; i<=4; i++)
  85. {
  86. pointsLA += LA[i].getPoints();
  87. pointsMH += MH[i].getPoints();
  88. }
  89. System.out.println("LA : MH = " +pointsLA +":" +pointsMH);
  90. if (pointsLA > pointsMH)
  91. System.out.println("The winner is team LA.");
  92. else
  93. System.out.println("The winner is team MH.");
  94.  
  95. player MVPLA = player.MVP(LA);
  96. player MVPMH = player.MVP(MH);
  97. if(MVPMH.getPoints() > MVPLA.getPoints())
  98. {
  99. System.out.println("MVP is " + MVPMH.getName() + " from MH" +" with " + MVPMH.getPoints() + " points");
  100. }
  101. else
  102. {
  103. System.out.println("MVP is " + MVPLA.getName() + " from LA" +" with " + MVPLA.getPoints() + " points");
  104. }
  105.  
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement