
Originally Posted by
DryasFatalis
Code:
import java.util.Scanner;
import javax.swing.JOptionPane;
import java.io.File;
import java.io.IOException;
public class BattingStatistics
{
public static void main (String [] args)throws IOException
{
final int SENTINEL = -1;
int AB, BB, B1, B2, B3, B4, HP, SC;
double BA, SP, OBP;
String stats = JOptionPane.showInputDialog( null, "Please enter the file name.");
File statsFile = new File(stats);
Scanner scan = new Scanner(statsFile);
scan.nextLine();
}
}
//this is what I have so far.
My Java is extremely rusty and we didn't have this fancy Scanner class when I was a little whipper-snapper but just from a really quick glace at the docs try something like this:
Code:
import java.util.Scanner;
import javax.swing.JOptionPane;
import java.io.File;
import java.io.IOException;
public class BattingStatistics
{
public static void main (String [] args)throws IOException
{
final int SENTINEL = -1;
int AB, BB, B1, B2, B3, B4, HP, SC, abOrSent;
double BA, SP, OBP;
AB = BB = B1 = B2 = B3 = B4 = HP = SC = BA = SP = OBP = 0;
String stats = JOptionPane.showInputDialog( null, "Please enter the file name.");
File statsFile = new File(stats);
Scanner scan = new Scanner(statsFile);
while( (abOrSent = scan.nextInt()) != SENTINEL)
{
AB += abOrSent;
BB += scan.nextInt();
B1 += scan.nextInt();
....do this till you get to the end
}
//Do your overall calcs here
//Display here
}
}
Bookmarks