I'm having a small problem getting variables from outfiles to produce a Dialog Box. I have to get the number of teams in each outfile and print them out in a dialog box. Along with the best and worst team based on their win percentage. The book I have explains nothing on the subject, nor has the web been any help so far. Anyone have any suggestions on where I'm going wrong? Heres my code:
import java.io.*;
import java.text.DecimalFormat;
import java.util.*;
import javax.swing.JOptionPane;
public class postlab4
{
public static void main(
String[] args)throws FileNotFoundException, IOException
{
double win;
double loss;
double record;
String teamname;
String inputString;
StringTokenizer tokenizer;
BufferedReader inFile = new
BufferedReader(new FileReader("list.dat"));
PrintWriter outFile = new
PrintWriter(new FileWriter("top.dat"));
PrintWriter outLossFile = new
PrintWriter(new FileWriter("bottom.dat"));
DecimalFormat twoDecimal = new
DecimalFormat("0.00");
inputString = inFile.readLine();
tokenizer = new StringTokenizer(inputString);
teamname = tokenizer.nextToken();
win = Integer.parseInt(tokenizer.nextToken());
loss = Integer.parseInt(tokenizer.nextToken());
record = win / (win + loss);
if (record > .5)
outFile.println(teamname + " " + twoDecimal.format(record));
else if (record <= .5)
outLossFile.println(teamname + " " + twoDecimal.format(record));
inputString = inFile.readLine();
while(inputString != null)
{
tokenizer = new StringTokenizer(inputString);
teamname = tokenizer.nextToken();
win = Integer.parseInt(tokenizer.nextToken());
loss = Integer.parseInt(tokenizer.nextToken());
record = win / (win + loss);
inputString = inFile.readLine();
if (record > .5)
outFile.println(teamname + " " + twoDecimal.format(record));
else if (record <= .5)
outLossFile.println(teamname + " " + twoDecimal.format(record));
else;
}
outLossFile.close();
outFile.close();
JOptionPane.showMessageDialog( null, "There are " + " " + " winning teams" + "\n"
+ "There are " + " " + " losing teams" + "\n" + "The best team is: " + " " + " they have a " + " " + " winning percentage" +
"\n" + "The bottom team is: " + " " + " they have a " + " " + " winning percentage", "Football Stats", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}