Guest User

j

a guest
Oct 21st, 2013
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.73 KB | None | 0 0
  1. import java.util.*;
  2. public class League
  3. {
  4.     public static void ListMatches(List TeamList)
  5.     {
  6.         int num_of_teams = 12;
  7.         int num_of_days = num_of_teams-1;
  8.         int half_size_of_team = num_of_teams/2;
  9.  
  10.         List teams = new ArrayList();
  11.         List matches = new ArrayList();
  12.         List derbymatches = new ArrayList();
  13.        
  14.         teams.addAll(TeamList);    
  15.         teams.remove(0);
  16.  
  17.         int teamSize = teams.size();
  18.  
  19.         for(int day = 0; day < num_of_days; day++)
  20.         {
  21.             System.out.println("Day {0} " + (day + 1));
  22.             int teamIdx = day % teamSize;
  23.  
  24.             //for the first team in each day, match it with team 1
  25.             matches.add(teams.get(teamIdx)+"/"+TeamList.get(0));
  26.  
  27.             for(int i=1; i < half_size_of_team; i++)
  28.             {
  29.                     int firstTeam = (day + 1) % teamSize;
  30.                     int secondTeam = (day + teamSize - i) % teamSize;
  31.                     matches.add(teams.get(firstTeam)+"/"+teams.get(secondTeam));
  32.             }
  33.         }
  34.        for(int i =0; i<matches.size(); i++)
  35.        {
  36.             String temp = matches.get(i).toString();
  37.             if(isLastMatchDerby(temp) && isMatchDerby(temp))
  38.             {
  39.                 System.out.println("This match " + temp + "is a derby");
  40.                 derbymatches.add(temp);
  41.                 continue;
  42.             }
  43.             else
  44.             {
  45.                 System.out.println(temp);
  46.             }
  47.         }
  48.        if(derbymatches.size() > 0)
  49.        {
  50.            System.out.println("I still have items left...");
  51.           for(int i = 0; i<derbymatches.size(); i++)
  52.           {
  53.               String temp = derbymatches.get(i).toString();
  54.               System.out.println(temp);
  55.           }
  56.        }
  57.     }  
  58.     public static void main(String[] args)
  59.     {
  60.         List TeamList = new ArrayList();
  61.         TeamList.add("Team A");TeamList.add("Team B");TeamList.add("Team C");TeamList.add("Team D");
  62.         TeamList.add("Team E");TeamList.add("Team F");TeamList.add("Team G");TeamList.add("Team H");
  63.         TeamList.add("Team I");TeamList.add("Team K");TeamList.add("Team L");TeamList.add("Team M");
  64.         ListMatches(TeamList);    
  65.     }
  66.    
  67.     public static boolean isLastMatchDerby(String par)
  68.     {
  69.         String pars[] = par.split("/");
  70.         String a = pars[0];
  71.         String b = pars[1];
  72.        
  73.         if(a == "Team A" && b == "Team G")
  74.             return true;
  75.         if(a == "Team G" && b == "Team A")
  76.             return true;
  77.         if(a == "Team C" && b == "Team D")
  78.             return true;
  79.         if(a == "Team D" && b == "Team C")
  80.             return true;
  81.         if(a == "Team C" && b == "Team E")
  82.             return true;
  83.         if(a == "Team E" && b == "Team C")
  84.             return true;
  85.         if(a == "Team D" && b == "Team E")
  86.             return true;
  87.         if(a == "Team E" && b == "Team D")
  88.             return true;
  89.        
  90.         return false;
  91.     }
  92.      public static boolean isMatchDerby(String par)
  93.     {
  94.         String pars[] = par.split("/");
  95.         String a = pars[0];
  96.         String b = pars[1];
  97.        
  98.         if(a == "Team A" && b == "Team G")
  99.             return true;
  100.         if(a == "Team G" && b == "Team A")
  101.             return true;
  102.         if(a == "Team C" && b == "Team D")
  103.             return true;
  104.         if(a == "Team D" && b == "Team C")
  105.             return true;
  106.         if(a == "Team C" && b == "Team E")
  107.             return true;
  108.         if(a == "Team E" && b == "Team C")
  109.             return true;
  110.         if(a == "Team D" && b == "Team E")
  111.             return true;
  112.         if(a == "Team E" && b == "Team D")
  113.             return true;
  114.        
  115.         return false;
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment