Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class player
- {
- private String Name;
- private String Team;
- private int Points;
- player (String name, String team)
- {
- this.Name = name;
- this.Team = team;
- this.Points = (int)(Math.random()*100) % 50;
- }
- public String getName ()
- {
- return Name;
- }
- public void setName (String n)
- {
- Name = n;
- }
- public int getPoints ()
- {
- return Points;
- }
- public void setPoints (int p)
- {
- Points = p;
- }
- public static player MVP(player[] plarray)
- {
- int maxpoints = 0, index = -1;
- for(int i = 0; i < plarray.length; i++){
- if(maxpoints < plarray[i].getPoints()){
- maxpoints = plarray[i].getPoints();
- index = i;
- }
- }
- player returner = plarray[index];
- return returner;
- }
- }
- public class practice {
- public static void main(String[] args)
- {
- player LA [] = new player [5];
- LA[0] = new player ("player_1", "LA");
- LA[1] = new player ("player_2", "LA");
- LA[2] = new player ("player_3", "LA");
- LA[3] = new player ("player_4", "LA");
- LA[4] = new player ("player_5", "LA");
- player MH[] = new player [5];
- MH[0] = new player ("player_1", "MH");
- MH[1] = new player ("player_2", "MH");
- MH[2] = new player ("player_3", "MH");
- MH[3] = new player ("player_4", "MH");
- MH[4] = new player ("player_5", "MH");
- int pointsLA = 0;
- int pointsMH = 0;
- for (int i=0; i<=4; i++)
- {
- System.out.println("Player from team LA: " +LA[i].getName() + " his points: " +LA[i].getPoints());
- }
- System.out.println();
- for (int i=0; i<=4; i++)
- {
- System.out.println("Player from team MH: " +MH[i].getName() + " his points: " +MH[i].getPoints());
- }
- for (int i = 0; i<=4; i++)
- {
- pointsLA += LA[i].getPoints();
- pointsMH += MH[i].getPoints();
- }
- System.out.println("LA : MH = " +pointsLA +":" +pointsMH);
- if (pointsLA > pointsMH)
- System.out.println("The winner is team LA.");
- else
- System.out.println("The winner is team MH.");
- player MVPLA = player.MVP(LA);
- player MVPMH = player.MVP(MH);
- if(MVPMH.getPoints() > MVPLA.getPoints())
- {
- System.out.println("MVP is " + MVPMH.getName() + " from MH" +" with " + MVPMH.getPoints() + " points");
- }
- else
- {
- System.out.println("MVP is " + MVPLA.getName() + " from LA" +" with " + MVPLA.getPoints() + " points");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement