title: Making a football standings from infinite match list input
body: <p>I have an assignment which I have to program that creates a standings table from match list input. I used the word &quot;infinite&quot; because input size is unknown so I have to create a program that works until there's no matches left. I created a football class for this(input contains 2 other sports and their own matches and teams indicating the sports type with first letter of the sport with &quot;F, B, V&quot; for example, they're only different in scoring part, so I though if I can make football work, I can make anything else work) that contains everything required in standings table, and methods for match results which looks like this:</p>
  <pre><code>public class Football {
      private int scoredGoals;
      private int receivedGoals;
      private String teamName;
      private int Score;
      private int wins;
      private int losses;
      private int MatchCount;
      private int draws;
      
      public void teamValues(String teamName, int Sgoals, int Rgoals) {
          this.teamName = teamName;
          this.scoredGoals = Sgoals;
          this.receivedGoals = Rgoals;
          
      }           
  
      public void matched() {
          MatchCount++;
      }
      
      public void winner() {
          wins++;
      }
      
      public void draw() {
          draws++;
      }
      
      public void loser() {
          losses++;
      }
      
      
      public void winScore() {
          Score += 3;
      }
      
      public void drawScore() {
          Score += 1;
      }
          
      
      public String showTeams() {
          return (teamName + &quot;    &quot; + MatchCount + &quot;  &quot; + wins + &quot;    &quot; + draws + &quot;   &quot; + losses + &quot;  &quot; + scoredGoals+&quot;:&quot;+receivedGoals + &quot;   &quot; + Score);
      }
      
  }
  </code></pre>
  <p>And in main class I'm calling  methods in if blocks to calculate wins, score, matches count etc. And main looks like this:</p>
  <pre><code>import java.io.File;
  import java.io.FileNotFoundException;
  import java.util.HashSet;
  import java.util.Scanner;
  
  public class Main {
      
      public static void main(String[] args) throws FileNotFoundException {
          
          
          
          File file = new File(&quot;input.txt&quot;);
          Scanner scan = new Scanner(file);
          String fileString = &quot;&quot;;
          Football teams[] = new Football[2];
          HashSet&lt;String&gt; teamsArray = new HashSet&lt;String&gt;();
          
          
          
          while(scan.hasNextLine()) {
              fileString = scan.nextLine();
              String[] match = fileString.split(&quot;\\t|:&quot;);
              
              if(match[0].equals(&quot;F&quot;)) {
                  int team1score = Integer.valueOf(match[3].trim());
                  int team2score = Integer.valueOf(match[4].trim());
                  
                  teams[0] = new Football();
                  teams[0].teamValues(match[1], team1score, team2score);
                  teams[1] = new Football();
                  teams[1].teamValues(match[2], team2score, team1score);
                  teams[0].matched();
                  teams[1].matched();
                  if(team1score&gt;team2score) {
                      
                      teams[0].winner();
                      teams[1].loser();
                      
                      teams[0].winScore();
                  }
                  
                  if(team1score==team2score) {
                      teams[0].draw();
                      teams[1].draw();
                      
                      teams[0].drawScore();
                      teams[1].drawScore();
                  }
                  
                  if(team1score&lt;team2score) {
                      teams[1].winner();
                      teams[0].loser();
                      
                      teams[1].winScore();
                  }
              
              String team0 = teams[0].showTeams();
              String team1 = teams[1].showTeams();
              
              teamsArray.add(team0);
              teamsArray.add(team1);
              
          }   
      }
          scan.close();
      }   
  }
  </code></pre>
  <p>Since the input is static, I used arrays to work around. My problem with my code is I cant find a way to store my teams without duplicates and the variables that comes within and update whenever that team has another match.</p>
  <p>I tried;</p>
  <ul>
  <li>Storing them in a 2D string array but since the amount of teams is unknown I think it won't be a healthy way to approach to the problem.</li>
  <li>Storing them in a String[] array list, which ended up storing the adresses instead of the values of the teams.</li>
  <li>Set which I still use to check if at least the methods are working as intended.</li>
  </ul>
  <p>It feels like I hit the wall with this program and I need to start over, so any kind of advice is appreciated.</p>
  <p>Here's an example of input and output:</p>
  <pre><code>Input:
      Home Team       Guest Team         H : G
  F   Manchester U.   Chelsea            2 : 2
  F   Liverpool       Manchester City    3 : 2
  F   Leicester City  Everton            1 : 3
  V   Team A          Team B             3 : 0
  F   Tottenham       Liverpool          3 : 1
  B   Team B          Team A            90 : 96
  F   West Ham        Manchester U.      2 : 1
  F   Arsenal         Manchester City    0 : 2
  F   Chelsea         Arsenal            3 : 3
  
  Output: 
      Name          Matches Wins Draw Lose   Scored:Received Score
  1.  Manchester U.   10     6    2    2         27:22        20
  2.  Arsenal         10     6    2    2         25:24        20 
  3.  Chelsea         10     5    3    2         28:20        18
  4.  Liverpool       10     4    4    2         22:19        16
  5.  Tottenham       10     4    4    2         22:21        16
  </code></pre>
  <p>There are teams with same scores, because calculating average of scored and received goals is another way to sort the teams.</p>