0

Okay here is my question, I have an text file file which looks like this

BASKETBALL
John Jacob
58% 15points
FOOTBALL
Jason Smith
24% 1touchdown
BASKETBALL
Mark Ramos
23% 25points
BASEBALL
Isaac David
10% 2 homeruns
FOOTBALL
David Sarlo
10% 0 touchdowns

I am attempting to take a list like this and output something like this in a console and text file.

Sport: Name Stats
BASKETBALL John Jacob 58% 15points
BASKETBALL Mark Ramos 23% 25points
BASEBALL Isaac David 10% 2 homeruns
FOOTBALL Jason Smith 24% 1touchdown
FOOTBALL David Sarlo 10% 0 touchdowns

I was thinking that I could have the buffer reader to read the file. Right after that I am not sure what to do, I am thinking to read the line then compare it to BASKETBALL, FOOTBALL or BASEBALL string then add it to the appropriate array does that sound right? I am trying to create a new Basketball player football player and baseball player, who as certain attributes. I guess I have multiple questions, how do I get the next line in to match up with the correct player. Then move to the next line and do the same?

import java.io.*;
private static String[] basketball = new String[100];
private static String[] football = new String[100];
private static String[] baseball = new String[100]; 


public static void CreateTeamList()

{
BufferedReader in = new BufferedReader (new FileReader(fileName)); 
try {
 
while (line ! = null) 
{
 String line = in.readline();
    if (line == "BASKETBALL")
     {
       create new BasketnallPlayer;
     }
  if (line == "FOOTBALL")
    {
      create new FootballPlayer;
    }

  if (line == "BASEBALL")
    {
     create new BaseballPlayer;
    }




}

Edited by NICEGUY123: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Taywin
0

You need to create a Player class or something to hold all value you are looking for. Then in each line, you match the data and create an object and store it in your array. Oh, and you should use equals() method to compare string. It is safer.

// i.e.
if (line.equals("BASEBALL")  // for case sensitive

// or
if (line.equalsIgnoreCase("BASEBALL")  // for case in-sensitive
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.