Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 41
Like Tree1Likes

Thread: Importing from text file and creating objects from the text files !??

  1. #21
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Importing from text file and creating objects from the text files !??

    Do it one small step at a time:
    1) read records from file
    2)split each record in its parts
    3)use the parts of the record to build an object
    etc
    Start at 1). Write the code to do that. Print each record after reading it
    When that works move to 2) Use the Arrays class's toString() method to print out the String array that split creates:
    System.out.println("an ID "+ java.util.Arrays.toString(theArrayName));
    When that works move to 3)
    etc

    Which steps have you completed?
    What step are you working on now?
    If you don't understand my response, don't ignore it, ask a question.

  2. #22
    toiletpaper is offline Member
    Join Date
    May 2014
    Posts
    43
    Rep Power
    0

    Default Re: Importing from text file and creating objects from the text files !??

    Almost done with the source code...
    Last edited by toiletpaper; 05-25-2014 at 07:22 PM.

  3. #23
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Importing from text file and creating objects from the text files !??

    Can you list the steps that you need to do for the program?
    What steps have you completed?
    Which step are you now working on?
    If you don't understand my response, don't ignore it, ask a question.

  4. #24
    toiletpaper is offline Member
    Join Date
    May 2014
    Posts
    43
    Rep Power
    0

    Default Re: Importing from text file and creating objects from the text files !??

    I have read the data from the text file and stored them in vector "studentRecords".
    and the splitted Stuff into "holder" vector.

  5. #25
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Importing from text file and creating objects from the text files !??

    Where is the code that prints out each line after it is read?
    Where is the code for 2) that splits the line into parts?
    You need to do the steps in order. You can't skip any.
    If you don't understand my response, don't ignore it, ask a question.

  6. #26
    toiletpaper is offline Member
    Join Date
    May 2014
    Posts
    43
    Rep Power
    0

    Default Re: Importing from text file and creating objects from the text files !??

    Quote Originally Posted by Norm View Post
    Can you list the steps that you need to do for the program?
    What steps have you completed?
    Which step are you now working on?
    Same question as before i guess mate, when i prompt the user to enter the course number i wana know how to get the course's name, and i still havent figured it out yet

  7. #27
    toiletpaper is offline Member
    Join Date
    May 2014
    Posts
    43
    Rep Power
    0

    Default Re: Importing from text file and creating objects from the text files !??

    Quote Originally Posted by Norm View Post
    Where is the code for 2) that splits the line into parts?
    You need to do the steps in order. You can't skip any.
    for(int i=0; i<studentRecord.size(); i++)
    {
    StringTokenizer to = new StringTokenizer ((String) studentRecord.elementAt(i));
    while(to.hasMoreElements())
    {
    holder.addElement(to.nextToken("|"));

    }
    The tokenizer splits it, so you get the vector: [BS, 343, Intro to marketing, etc, etc] Every Attribute in 1 empty space inside the vector "HOLDER", while inside studentRecords, there is [BS|343|intro toMarketing, BS|343|LAB Intro to marketing, etc.]

  8. #28
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Importing from text file and creating objects from the text files !??

    Post what is printed out when the line is read
    and what is split out of that line

    so you can see that the code is doing those steps correctly.


    i wana know how to get the course's name,
    That must be a step way past step 4. Don't worry about those steps yet. You need to get the first steps working:
    1) and 2) and 3) etc
    If you don't understand my response, don't ignore it, ask a question.

  9. #29
    toiletpaper is offline Member
    Join Date
    May 2014
    Posts
    43
    Rep Power
    0

    Default Re: Importing from text file and creating objects from the text files !??

    ....
    Last edited by toiletpaper; 05-25-2014 at 06:53 PM. Reason: edited back original contents for the flow of the thread

  10. #30
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Importing from text file and creating objects from the text files !??

    Can you add a String to each output to identify it and allow it to be seen separate from other data that is printed?
    I can not tell anything from the contents of post#29
    Something like this:
    Java Code:
    line = br.readLine();
    System.out.println("line="+line+"<");
    ...
    String tkn = to.nextToken();
    System.out.println("tkn="+tkn);
    If you don't understand my response, don't ignore it, ask a question.

  11. #31
    toiletpaper is offline Member
    Join Date
    May 2014
    Posts
    43
    Rep Power
    0

    Default Re: Importing from text file and creating objects from the text files !??

    Quote Originally Posted by Norm View Post
    Can you add a String to each output to identify it and allow it to be seen separate from other data that is printed?
    I can not tell anything from the contents of post#29
    Something like this:
    Java Code:
    line = br.readLine();
    System.out.println("line="+line+"<");
    ...
    String tkn = to.nextToken();
    System.out.println("tkn="+tkn);
    Sorry, my pc shutdown cuz i was updating my graphic card driver. Anws here it is:


    PHP Code:
    line=BS|343|Intr. to Marketing|TR|02:00pm-03:15pm|Peter Morok<
    line=BS|343|LAB Intr. to Marketing|T|05:00pm-07:50pm|Peter Morok<
    line=BS|410|Advanced Marketing|MWF|11:00am-11:50am|John Led<
    line=BS|410|Lab Advanced Marketing|M|04:30pm-7:20pm|John Led<
    line=BS|426|International Business|MWF|10:00am-10:50am|John Led<
    line=BS|475|Business Management|TR|11:00 am-12:15pm|John Led<
    line=BS|543|Micro|TR|09:30am-10:45am|John Led<
    line=null<
    tkn=343
    tkn=TR
    tkn=Peter Morok
    tkn=343
    tkn=T
    tkn=Peter Morok
    tkn=410
    tkn=MWF
    tkn=John Led
    tkn=410
    tkn=M
    tkn=John Led
    tkn=426
    tkn=MWF
    tkn=John Led
    tkn=475
    tkn=TR
    tkn=John Led
    tkn=543
    tkn=TR
    tkn=John Led

  12. #32
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Importing from text file and creating objects from the text files !??

    Why aren't all the parts of the line shown as tkns?
    There are several missing parts.
    line=BS|343|Intr. to Marketing|TR|02:00pm-03:15pm|Peter Morok<
    tkn=343
    tkn=TR
    tkn=Peter Morok

    Where are the following?
    BS
    Intr. to Marketing
    02:00pm-03:15pm

    It would make more sense in the code to read a line and split it immediately rather than save the line and then loop through them again to split them.
    If you don't understand my response, don't ignore it, ask a question.

  13. #33
    toiletpaper is offline Member
    Join Date
    May 2014
    Posts
    43
    Rep Power
    0

    Default Re: Importing from text file and creating objects from the text files !??

    They actually inside the vector but the line of code u gave me made them split like that...


    "String tkn = to.nextToken();
    System.out.println("tkn="+tkn);"

    This is the vector: [BS, Intr. to Marketing, 02:00pm-03:15pm, BS, LAB Intr. to Marketing, 05:00pm-07:50pm, BS, Advanced Marketing, 11:00am-11:50am, BS, Lab Advanced Marketing, 04:30pm-7:20pm, BS, International Business, 10:00am-10:50am, BS, Business Management, 11:00 am-12:15pm, BS, Micro, 09:30am-10:45am]

  14. #34
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Importing from text file and creating objects from the text files !??

    The code I posted was NOT supposed to be used directly. It was an example that needed to be reworked to fit in the code.
    If you don't understand my response, don't ignore it, ask a question.

  15. #35
    toiletpaper is offline Member
    Join Date
    May 2014
    Posts
    43
    Rep Power
    0

    Default Re: Importing from text file and creating objects from the text files !??

    I'll try to work something out myself, im almost ready to give up, ive been working for 4-5 hours and completed nothing woohoo awesome major, fml! (ill probably post the end result when im done, that is if i'll ever finish the damn thing)

  16. #36
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: Importing from text file and creating objects from the text files !??

    The OP edited out (repeatedly) the content of the data he's using; it disturbs the flow of the discussion too much for the other readers; @OP: don't do that anymore, it's not just you and some machine; there are other readers involved who might want to participate in this thread and maybe solve your problem; I put back the original content in this separate reply:

    Quote Originally Posted by data
    [CSC, 243, Intr. Object Oriented Program., TR, 02:00pm-03:15pm, Joseph T. Khalifeh, CSC, 243, LAB Intr. Object Oriented Program., T, 05:00pm-07:50pm, TBA, CSC, 310, Algorithms & Data Structures, MWF, 11:00am-11:50am, Danielle A. Azar, CSC, 310, Lab Algorithms & Data Structures, M, 04:30pm-7:20pm, TBA, CSC, 326, Operating Systems, MWF, 10:00am-10:50am, Danielle A. Azar, CSC, 375, Database Management Systems, TR, 11:00 am-12:15pm, Haidar M. Harmanani, CSC, 443, Web Programming, TR, 09:30am-10:45am, Haidar M. Harmanani ]

    Vector "studentRecord" (UnTokenized)
    [, CSC|243|Intr. Object Oriented Program.|TR|02:00pm-03:15pm|Joseph T. Khalifeh, CSC|243|LAB Intr. Object Oriented Program.|T|05:00pm-07:50pm|TBA, CSC|310|Algorithms & Data Structures|MWF|11:00am-11:50am|Danielle A. Azar, CSC|310|Lab Algorithms & Data Structures|M|04:30pm-7:20pm|TBA, CSC|326|Operating Systems|MWF|10:00am-10:50am|Danielle A. Azar, CSC|375|Database Management Systems|TR|11:00 am-12:15pm|Haidar M. Harmanani, CSC|443|Web Programming|TR|09:30am-10:45am|Haidar M. Harmanani ]
    Jos
    cenosillicaphobia: the fear for an empty beer glass

  17. #37
    toiletpaper is offline Member
    Join Date
    May 2014
    Posts
    43
    Rep Power
    0

    Default Re: Importing from text file and creating objects from the text files !??

    Quote Originally Posted by JosAH View Post
    The OP edited out (repeatedly) the content of the data he's using; it disturbs the flow of the discussion too much for the other readers; @OP: don't do that anymore, it's not just you and some machine; there are other readers involved who might want to participate in this thread and maybe solve your problem; I put back the original content in this separate reply:



    Jos
    That post was irrelevant, i miscopied the output
    Last edited by toiletpaper; 05-25-2014 at 07:10 PM.

  18. #38
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Importing from text file and creating objects from the text files !??

    Did you ever do some design work and make a list of the steps the code needs to do for the assignment?
    Without a design for the code, it will be harder to write the code.
    If you don't understand my response, don't ignore it, ask a question.

  19. #39
    toiletpaper is offline Member
    Join Date
    May 2014
    Posts
    43
    Rep Power
    0

    Default Re: Importing from text file and creating objects from the text files !??

    I just have 1 more question, How is it possible to edit the text file ? Like delete a line from the text file let's suppose, how do you actually delete it IN the text file itself.

    In other words, how can you make a new text file with the modifications that you've made, and delete the old one ?

  20. #40
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Importing from text file and creating objects from the text files !??

    edit the text file
    One way is to read all the lines into the program, make the changes to them as needed, then write the new lines back to the file, replacing all of what was there with the new lines.
    If you don't understand my response, don't ignore it, ask a question.

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Replies: 3
    Last Post: 06-04-2012, 05:31 AM
  2. Replies: 1
    Last Post: 06-04-2012, 05:01 AM
  3. read from text file into array of objects
    By janey4115 in forum New To Java
    Replies: 1
    Last Post: 11-20-2011, 12:40 PM
  4. Creating Ouput Text File
    By Raian in forum New To Java
    Replies: 14
    Last Post: 05-24-2010, 09:56 AM
  5. creating a graph from a text file
    By chinolee in forum New To Java
    Replies: 3
    Last Post: 11-23-2009, 08:36 AM

Posting Permissions

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