1 Attachment(s)
Match Generator Assignment Help / Error Message
Hiya guys, I've been ill recently and not had time to finish my assignment, my tutor has given me a reaessment and I really can't fail it, so far I've got 30/40 points for the module. The last 10 points are for valiadation which I am stuck on.
My current assignment is a football match generator, I scan a file and store the data, I then output the data to read football teams scores which is working fine but for the last 10 points I need to be able to validate the data so it read the scores correctly from the fake and real once. I'm new to this forum so not really sure what to do and I'm also new to programming so I'm not that epic at it =/
Can anyone help me at all? I really can't fail this module!
Kitty x
Below is my current code and the error message I have.
Code:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class requirement1 {
public class Teams {
String home_team;
String away_team;
int home_score;
int away_score;
}
public static void main(String[] args) throws FileNotFoundException {
// scans the file named in brackets
Scanner s = new Scanner(new File("src/results2.txt"));
String line; // stores the each line of text read from the file
//declaring all values
int InvalidCount = 0; // declares all the variables which are set to 0
int ValidCount = 0;
int ScoreCount = 0;
while ( s.hasNext() ) {
line = s.nextLine();
String [] splitupText = line.split(":");
line = line.trim();
// trims all the text
splitupText[0]=splitupText[0].trim();
splitupText[1]=splitupText[0].trim();
if (splitupText.length != 4)
{InvalidCount = InvalidCount+1 ;}
else if (splitupText[0].isEmpty() ){
InvalidCount = InvalidCount+1 ;}
else if (splitupText[1].isEmpty() ){
InvalidCount = InvalidCount+1 ;}
else {
String hometeamName = splitupText[0].trim();
String awayteamName = splitupText[1].trim();
String hometeamScore = splitupText[2].trim();
String awayteamScore = splitupText[3].trim();
try { // parses all the data from the file
int homescore = Integer.parseInt(hometeamScore);
int awayscore = Integer.parseInt(awayteamScore);
ScoreCount = ScoreCount + (homescore + awayscore);
System.out.println( hometeamName + " [" + hometeamScore + "] " + "| "+ awayteamName + " [" + awayteamScore + "]"); // prints all the data from the .txt file in the given format
ValidCount = ValidCount+1 ;
}
catch (NumberFormatException e) {
InvalidCount = InvalidCount+1 ;
}
}
}
System.out.println( ("\n") ); // prints a blank line
System.out.println ("Number of Goals: " + ScoreCount);
System.out.println ("Number of invalid entries: " + InvalidCount);
System.out.println ("Number of valid entries: " + ValidCount);
}}
Error Message
Code:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at requirement1.main(requirement1.java:39)
I've also attached the file that I read the data off.