Advertisement
Guest User

Untitled

a guest
Mar 28th, 2012
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 KB | None | 0 0
  1. public class Project3 {
  2.  
  3.     public static void main(String[] args) {
  4.     Input3 input = new Input3();
  5.     Team teams[] = new Team[input.NUMBER_OF_TEAMS];
  6.     Player players[] = new Player[input.NUMBER_OF_PLAYERS];
  7.     String playas[] = new String[input.NUMBER_OF_PLAYERS];
  8.     String temp;
  9.  
  10.     for ( int i=0 ; i<3 ; i++ ) {
  11.         String name = input.getNextString();
  12.         for ( int j=0 ; j<5 ; j++ )
  13.             playas[j] = input.getNextString();
  14.         teams[i] = new Team(name, playas);
  15.         teams[i].sortPlayers();
  16.         System.out.println(teams[i]);
  17.         }
  18.     }
  19. }
  20.  
  21. ////////////////////////////
  22.  
  23. public class Player {
  24.  
  25.     public String[] name;
  26.  
  27.     public Player(String inputname) {
  28.  
  29.         name = inputname.split(" ");
  30.  
  31.     }
  32.     public String[] getName() {
  33.         return name;
  34.     }
  35.  
  36.     public String getFirstName() {
  37.         return name[0];
  38.     }
  39.  
  40.     public String getLastName() {
  41.         String last = name[1];
  42.         return "Baker";
  43.     }
  44. }
  45.  
  46. ///////////////////////////
  47.  
  48. public class Team {
  49.     private String name;
  50.     public Player players[];
  51.     public Player temp;
  52.  
  53.     public Team(String inputname, String playas[]) {
  54.  
  55.         inputname = name;
  56.         players = new Player [playas.length];
  57.         for( int k=0 ; k<playas.length ; k++ )
  58.             this.players[k] = new Player(playas[k]);
  59.  
  60.     }
  61.  
  62.     public void sortPlayers() {
  63.         int n = players.length;
  64.  
  65.         for (int pass=1; pass < n; pass++){
  66.             for (int i=0; i < n-pass; i++) {
  67.                 String playerName = players[i].getLastName();
  68.                 String nextPlayerName = players[i+1].getLastName();
  69.                 if(playerName.compareTo(nextPlayerName) > 0)
  70.                 temp = players[i];
  71.             players[i] = players[i+1];
  72.             players[i+1] =  temp;
  73.             }
  74.         }
  75.     }
  76. }
  77.  
  78. //Input3 class goes here. Assume it works, and returns strings in the form of "Firstname Lastname"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement