I have the following information I am trying to read from a .txt file
Griffey HHOHOKWOHKSPOOWSH
Piazza OOHHHKPSOHOOHWWHO
Pudge HHHHKOOHHHSWWHHOP
I need to be able to separate the name, then each individual letter (preferably from something like a charAt. Each letter stands for a Hit, Out, Walk, Hit by Pitch, or Strikeout. I have to calculate each player's Batting Average, On Base Percentage, #Hits, #Walks, #Hit by Pitch. Finally I have to find the leaders of the 3 in each category.
So far, I am really stuck on being able to separate the names and plucking out each individual letter.
Here is my code so far:
import java.util.*;
public class readStats
{
public static void main(String[] args) throws Exception
{
//Pull stats.txt File
java.io.File file = new java.io.File("stats.txt");
//Create Scanner
Scanner input = new Scanner(file);
//Read data from file
while (input.hasNextLine())
{
String name1 = input.next();
String griffey1 = input.nextLine();
char batArray = griffey1.charAt(0);
//char griffey2 = input.next().charAt(1);
System.out.print(name1);
//System.out.println(griffey1);
//System.out.println(batArray[1]);
}
}
}
My output is:
GriffeyPiazzaPudge
UPDATE
Okay I have variables for each "item" now with this code:
import java.util.*;
public class readStats
{
public static void main(String[] args) throws Exception
{
//Pull stats.txt File
java.io.File file = new java.io.File("stats.txt");
//Create Scanner
Scanner input = new Scanner(file);
//Read data from file
while (input.hasNextLine())
{
String name1 = input.next();
String stats1 = input.next();
String name2 = input.next();
String stats2 = input.next();
String name3 = input.next();
String stats3 = input.next();
System.out.println(name1);
System.out.println(stats1);
System.out.println(name2);
System.out.println(stats2);
System.out.println(name3);
System.out.println(stats3);
}
}
}
Output:
Griffey
HHOHOKWOHKSPOOWSH
Piazza
OOHHHKPSOHOOHWWHO
Pudge
HHHHKOOHHHSWWHHOP