Results 1 to 4 of 4
  1. #1
    wansai is offline Member
    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Default How to create a table in a text file and parse it into a Java Application

    I have an assignment to do. I have to create a table of data(which is about Englisg Premier League) and in a table must contains:

    • Team Name.
    • Total number of games played to date.
    • Total number of games the team has won at home to date.
    • Total number of games the team has lost at home to date.
    • Total number of goals the team has scored at home to date.
    • Total number of goals the team has conceded at home to date.
    • Total number of games the team has won away from home to date.
    • Total number of games the team has drawn away from home to date.
    • Total number of games the team has lost away from home to date.
    • Total number of goals the team has scored away from home to date.
    • Total number of goals the team has conceded away from home to date.
    • Total number of points the team as accumulated to date.
    (I have no problem to find such details. )

    Once i have all of the details I need to put them into a table in a text file.
    So I don't quite understand how to create a table in a text file or i just have to create a simple text file and then convert it in to a table?
    I have no problem to read simple text file and display it on the Java Apllication but in this case i dont even know how to start off.

    Is any have any idea how to do it?
    Please advise me, I really need to know how to do it. Thanks

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: How to create a table in a text file and parse it into a Java Application

    This looks like a plain csv file to me:
    Arsenal;22;8;2;32;9;6;1;3;22;11;43
    ManU;22;10;1;32;9;5;1;3;22;11;46
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    CA, USA
    Posts
    264
    Rep Power
    6

    Default Re: How to create a table in a text file and parse it into a Java Application

    Definitely look into csv files. But, for now I'll explain a simplistic way of doing it:

    In your text file, each line should be a single team. Each attribute of that team should be separated by some character, let's say a semicolon.

    So, as you read in the text file line by line, you would want to "split" the line into a multiple strings divided ("delimited") by semicolons.

    Let's say you read in a line:
    String line = in.nextLine();

    And this line has the value "teamname;12;34;56;78;90"
    You can use String.split() to turn it into an array

    String[] lines = line.split(";");

    Now, lines is an array of Strings containing: "teamname", "12", "34", "56", "78", "90"

    Hope this helps somewhat.

  4. #4
    wansai is offline Member
    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Default Re: How to create a table in a text file and parse it into a Java Application

    Quote Originally Posted by AndrewM16921 View Post
    Definitely look into csv files. But, for now I'll explain a simplistic way of doing it:

    In your text file, each line should be a single team. Each attribute of that team should be separated by some character, let's say a semicolon.

    So, as you read in the text file line by line, you would want to "split" the line into a multiple strings divided ("delimited") by semicolons.

    Let's say you read in a line:
    String line = in.nextLine();

    And this line has the value "teamname;12;34;56;78;90"
    You can use String.split() to turn it into an array

    String[] lines = line.split(";");

    Now, lines is an array of Strings containing: "teamname", "12", "34", "56", "78", "90"

    Hope this helps somewhat.
    This helps me Andrew, thanks a lot of this.

    But one more thing that i would like to ask you what if i want to just display a summary of its content like:
    - Team name.
    - Total number of games played to date.
    - The total number of games the team has won to date (taking into account games at home and away).
    - The total number of games the team has drawn to date (taking into account games at home and away).
    - The total number of games the team has lost to date (taking into account games at home and away).
    - The teams goal difference (that is, goals scored minus goals conceded). This figure must be inclusive of games play at home and away and may be a negative value.
    - Total number of points the team has accumulated.

    It'll be a part of calculation as well. I guess a simplistic way of displying text file wouldn't do, right?
    Could you give me an idea how to do it, please?
    Thanks again for this and sorry for bothering you

Similar Threads

  1. Parse structured text file
    By mcdhappy80 in forum New To Java
    Replies: 11
    Last Post: 12-26-2012, 02:52 AM
  2. Create a Text file with java.
    By javaforums1 in forum New To Java
    Replies: 1
    Last Post: 10-06-2012, 03:24 PM
  3. Conveting a Text File to a Table
    By tudorH in forum JDBC
    Replies: 8
    Last Post: 02-26-2010, 06:41 AM
  4. Replies: 5
    Last Post: 08-25-2009, 08:43 AM
  5. Use Scanner to parse text file, adding to HashMap
    By JordashTalon in forum New To Java
    Replies: 0
    Last Post: 03-04-2009, 11:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •