1 Attachment(s)
Extracting and displaying data from a text file
Hi all
I was wondering if anyone would be able to give me a little bit of help and advice with something I'm having a bit of trouble with. I'm a Java newbie and what I'm trying to do is perhaps a little advanced for me.
What I am trying to do is extract data from a text file containing football results (please see attachment) and display information regarding a specific team. I am fine up until the point where I have split the data into its component parts, but I am completely stumped as to actually displaying the data as I would like. I am just trying to keep this as basic as possible at the moment. Please take a look at what I have so far:
Code:
import java.util.Scanner;
import java.io.*;
public class Results
{
public static void main (String[] args) throws FileNotFoundException
{
new File("team.html").delete();
Scanner scan = new Scanner(System.in);
System.out.print("Select a specific team: ");
String team = scan.nextLine();
System.out.print("Select (H)TML or (P)lain text output: ");
String f = scan.nextLine();
String format = f.toUpperCase();
{
Scanner s = new Scanner(new File("results.txt"));
String hteam;
String ateam;
int hgoals;
int agoals;
String line;
while (s.hasNext())
{
line = s.nextLine();
String[] splitupText = line.split(" : ");
if (splitupText.length==4)
{
{
hteam = splitupText[0].trim();
ateam = splitupText[1].trim();
hgoals = Integer.parseInt(splitupText[2].trim());
agoals = Integer.parseInt(splitupText[3].trim());
}
[COLOR="Blue"]if(format.equals("P"))[/COLOR]
{
}
}
}
}
}
}
In the section I've highlighted in blue, I need to somehow calculate and go on to display the following information for the user's chosen team, but I'm not really sure how to and would greatly appreciate a few pointers. I guess what is confusing me most is the chosen team could appear as either the home team (hteam) or away team (ateam) so the way the results are calculated is dependent on this factor.
Games played: (this should just be the total number of occurrances of the chosen team?)
Games won:
Games drawn:
Games lost:
Goals for:
Goals against:
Many thanks
fugazi