# Problem with calculation

• 11-24-2010, 05:07 PM
ibrafiqb
Problem with calculation
Hi, I am having problems with a code. Basically the code reads some information from a text file e.g:

Liverpool : Bradford : 1 : 3
Manchester : Chelsea : 4 : 5

etc....

It splits each bit down to four variables, so homeTeam, awayTeam, htScore & atScore. It has been programmed to count all the entries. At some point the program asks the user whether they would like to focus on all teams (as per the output above) or on a Specific team. So far if I put in a specific team i.e Liverpool, it calculates how many games Liverpool has played by using an if statement. However I need it to calculate how many games Liverpool or any other team depending on the team entered have won / lost etc etc. I am really struggling. I have posted the rest of the code underneath. Any suggestions guys? Thanks
• 11-24-2010, 05:18 PM
JosAH
Please edit your article so that the angular brackets in your <code> tags are replaced by square brackets.

kind regards,

Jos
• 11-24-2010, 05:26 PM
ibrafiqb
Quote:

Originally Posted by JosAH
Please edit your article so that the angular brackets in your <code> tags are replaced by square brackets.

kind regards,

Jos

Done for you, hope it helps! I have also uploaded the text file which the program will require to run... please use p for plain text at the moment only thanks.
• 11-24-2010, 06:02 PM
JosAH
Quote:

Originally Posted by ibrafiqb
Done for you, hope it helps! I have also uploaded the text file which the program will require to run... please use p for plain text at the moment only thanks.

Thanks, now your code is more readable (it contains a lot of empty lines though); I'd build a little class first:

Code:

```public class Match {   private String home;   private String visitors;   private int pros;   private int cons;   public Match(String home, String visitors, int pros, int cons) {       this.home= home;       this.visitors= visitors;       this.pros= pros;       this.cons= cons;   }   // rest of the code goes here, e.g. getters }```
I'd also keep a Map<String, List<Match>> where the key represents the home team and the value, a List of Matches, represents all the matches where the key is the home team. Then I'd think a bit more before I'd code the rest ...

kind regards,

Jos