# Thread: Problem with calculation

1. Member
Join Date
Nov 2010
Posts
3
Rep Power
0

## 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
Last edited by ibrafiqb; 11-24-2010 at 06:04 PM. Reason: students googling and copying work

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

kind regards,

Jos

3. Member
Join Date
Nov 2010
Posts
3
Rep Power
0
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.

4. 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:

Java 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

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•