Right, i'm doing a piece of work for uni and basically i need it to read in a set of results that are contained in a .txt file and split them at the delimiter (which i have managed to do). The problem is i need to take these results and organise them into a table which looks something like this :
<home_team_name> [<home_team_score>] | <away_team_name> [<away_team_score>]
Then i need to make sure that all of the scores read in were valid i.e. both names and both scores were there. If a team name or score was missing then it should not be output to the screen.
Finally at the end i need to output something that will say... "The valid match count was # . Total goals scored were #. Invalid match count was # .
I'm very new to java this is one of my first pieces of work. Would i need to split each of the names and scores into a seperate class? I'll post what code i have so far. Thanks!!
import java.io.FileReader; import java.io.BufferedReader; import java.io.IOException; public class linebased { public static void main(String[] args) throws IOException { BufferedReader inputStream = null; try { inputStream = new BufferedReader(new FileReader("results2.txt")); String text; while ((text = inputStream.readLine()) != null) { String [] splitupText = text.split(":"); // split the text into multiple elements for ( int i = 0; i < splitupText.length; i++ ) { // loop over each element String nextBit = splitupText[i]; // get the next element (indexed by i) nextBit = nextBit.trim(); // use the trim method to remove leading and trailing spaces System.out.println(nextBit); // display the next element } } } finally { if (inputStream != null) { inputStream.close(); } } } }