Can anyone help me with this assignment

input needs to be grabbed from file
Brazil 1 France 2
France 1 Germany 2
Germany 0 Japan 3
Germany 2 Brazil 0
France 4 Japan 4
Then the corresponding summary written to standard output should be:
Team W D L F A P
Germany 2 0 1 4 4 6
Japan 1 1 0 7 4 4
France 1 1 1 7 7 4
Brazil 0 0 2 1 4 0
For each team, the output contains the number of games won (W), the number of games drawn (D), the number of games lost (L), the total number of goals scored (F, "goals for"), the total number of goals scored by the teams' opponents (A, "goals against"), and the total number of points (P). A team scores 3 points for a win, 1 point for a draw, and 0 points for a loss.
The assignment suggest the use of maps but i am not sure how i can use maps to help me as i am relitivley new to the collections heirahcy.
here is the code that i have so far assembled.
import java.io.*;
import java.util.*;
class Soccer
     //declare varibles
     StringTokenizer st;                    // StringTokenizer for separating values
     BufferedReader in;                    // BufferedReader for reading standard input
     BufferedReader infile;               // reads data from input file
     String input;                    // holds input data temporarily
     int count;                              // String input to hold line details
     Map teams = new HashMap();          //creates a new hash map for holding data
     public static final Integer ONE = new Integer(1);     //for distinct wrods count
     String[] temp;
     public static void main (String [] args)
          Soccer app = new Soccer();
               app.input(args);
     }//end main
     public void input(String [] args)
          try{
               //standard output to screen
               in = new BufferedReader(new InputStreamReader(System.in));
               //input from filend class
               infile = new BufferedReader(new FileReader(args[0]));
               input = infile.readLine();
               st = new StringTokenizer(input);
               count = st.countTokens();
               temp = new String[count];
               for(int i = 0; i < count; i++)
                    temp[i] = st.nextToken();
               }//end for
               //start if map code
               Map map = new HashMap(); // Maps words to no. of occs.
               for (int i = 0; i < count; i++) {
                    // Get number of occurrences of next word
                    Integer value = (Integer) map.get(temp);
                    // Increment number of occurrences of word
                    if (value == null) {
                         map.put(temp[i], ONE);
                    } else {
                         int val = value.intValue();
                         map.put(temp[i], new Integer(val+1));
               }//end for
               // Print values of map, one per line
               Iterator it = map.keySet().iterator();
               while (it.hasNext() ) {
               Object key = it.next();
               System.out.println(key + " = " + map.get(key));
               } catch (IOException e){
                    System.out.println("ERROR: " + e.getMessage());
               //call the print method
               print();
     }//end input
     public void print()
          System.out.println("Team     W D L A P ");
     }//end print
}//end class

Pass the filename in as an argument.
import java.io.*;
import java.util.*;
public class Ivg1
     static class Team
          String name;
          int played;
          int won;
          int lost;
          int fore;
          int against;
          public int getDrawn() { return played-won-lost; }
          public int getPoints() { return (won*3)+getDrawn(); }
          public String toString() {
               return name +"\t" +won +" " +getDrawn() +" " +lost +" " +fore +
                    " " +against +" " +getPoints();
     public static void main(String[] argv)
          throws Exception
          BufferedReader reader= new BufferedReader(new FileReader(argv[0]));
          Hashtable teams= new Hashtable();
          for (String line= null; (line= reader.readLine()) != null;) {
               StringTokenizer st= new StringTokenizer(line);
               String homeTeam= st.nextToken();
               int homeScore= Integer.parseInt(st.nextToken());
               String awayTeam= st.nextToken();
               int awayScore= Integer.parseInt(st.nextToken());
               Team team1= (Team) teams.get(homeTeam);
               Team team2= (Team) teams.get(awayTeam);
               if (team1 == null) {
                    team1= new Team();
                    team1.name= homeTeam;
                    teams.put(team1.name, team1);
               if (team2 == null) {
                    team2= new Team();
                    team2.name= awayTeam;
                    teams.put(team2.name, team2);
               if (homeScore > awayScore) {
                    team1.won++;
                    team2.lost++;
               if (homeScore < awayScore) {
                    team1.lost++;
                    team2.won++;
               team1.played++;
               team1.fore += homeScore;
               team1.against += awayScore;
               team2.played++;
               team2.fore += awayScore;
               team2.against += homeScore;
          System.err.println("Team\tW D L F A P");
          TreeSet set= new TreeSet(new Comparator() {
               public int compare(Object o1, Object o2) {
                    return ((Team) o1).getPoints() < ((Team) o2).getPoints() ? 1 : -1;
          Iterator iterator= teams.values().iterator();
          while (iterator.hasNext())
               set.add(iterator.next());
          iterator= set.iterator();
          while (iterator.hasNext())
               System.err.println(iterator.next().toString());
}

Similar Messages

Maybe you are looking for