1. The official Sherdog Store is back! Check it out! » Discuss it here! »

need some homework help in Java

Discussion in 'Mayberry Lounge' started by MATT DAMON, Aug 18, 2015.

  1. MATT DAMON Blue Belt

    Joined:
    Jun 10, 2015
    Messages:
    552
    Likes Received:
    0
    I have a text file that I need to read.

    The text file has full name, middle initial, DOB, sex, and city born.

    I need to output the file.

    What is the best way for me to process the file?

    Do I create a person object? I think I should create the object, but then, I don't know where to store it.

    Any ideas?
     
  2. LatFlare EADC

    Joined:
    Jun 12, 2013
    Messages:
    7,474
    Likes Received:
    0
    Location:
    Watching a snail crawl along a straight razor.
    Try turning it off and then on again.
     
  3. Palpatine Brown Belt Platinum Member

    Joined:
    Dec 5, 2011
    Messages:
    3,832
    Likes Received:
    0
    Have you checked whether your computer is plugged in?
     
  4. Osculater Red Belt

    Joined:
    Aug 16, 2013
    Messages:
    8,353
    Likes Received:
    1,623
    Apple or mac?
     
  5. MATT DAMON Blue Belt

    Joined:
    Jun 10, 2015
    Messages:
    552
    Likes Received:
    0
    oh man, I posted to the wrong forum...these replies are hilarious...I should post more homework questions just for laughs...
     
  6. craxie Yellow Belt

    Joined:
    Aug 3, 2015
    Messages:
    209
    Likes Received:
    0
    your description is tremendously vague

    'output' how? to the screen? to a file? formatted a particular way? do you need to sort or process the records?
     
  7. LatFlare EADC

    Joined:
    Jun 12, 2013
    Messages:
    7,474
    Likes Received:
    0
    Location:
    Watching a snail crawl along a straight razor.
    Have you asked a literate person to read the text file to you?
     
  8. MATT DAMON Blue Belt

    Joined:
    Jun 10, 2015
    Messages:
    552
    Likes Received:
    0
    I need the output to the screen.

    I just need it formatted in this way:

    Name, DOB, Sex, Address.

    I think I need to process the records, but I don't know how to do it correctly.

    I would like to sort them, but how do I sort them? Do I treat the files as one big object, or sort them individually?
     
  9. MATT DAMON Blue Belt

    Joined:
    Jun 10, 2015
    Messages:
    552
    Likes Received:
    0
    This is the best comment ever!
     
  10. zackryder Long Island Iced Z Platinum Member

    Joined:
    Apr 27, 2012
    Messages:
    11,220
    Likes Received:
    0
    Location:
    Long Island, New York
  11. craxie Yellow Belt

    Joined:
    Aug 3, 2015
    Messages:
    209
    Likes Received:
    0
    obviously you should be using what you're being taught in class, but there are a ton of ways to do this

    i'm assuming the file is a csv or similar

    the simplest would just be to read each line, split into an array, and then print out the line with the array positions hard coded

    if you want to go fully fancy, create a person object with a constructor that takes the line and has comparator and print functions and add them to an arraylist, then you can sort the arraylist like so:
    http://stackoverflow.com/questions/10082123/using-comparator-to-order-arraylist-java
     
  12. MATT DAMON Blue Belt

    Joined:
    Jun 10, 2015
    Messages:
    552
    Likes Received:
    0
    Holy crap, dude! I was on stackoverflow earlier, and couldn't find what I wanted. This is what I was looking for, lol.

    I posted on sherdog because I was desperate to solve this Java problem, lol.

    Much thanks!!!!!
     
  13. Shogun Sakuraba Green Belt

    Joined:
    Jul 19, 2013
    Messages:
    1,069
    Likes Received:
    1
    Location:
    EX FEO MESSI
    From now on, please, use the Sherdog Java subforum.
     
  14. MATT DAMON Blue Belt

    Joined:
    Jun 10, 2015
    Messages:
    552
    Likes Received:
    0
    I will...Sherdog has some of the brightest programming tutors you could ever imagine! Thanks, Sherdog!
     
  15. mushishi A is a, a is a, should I save her?

    Joined:
    Mar 25, 2009
    Messages:
    14,773
    Likes Received:
    1
    Here you go:

    [​IMG]
     
  16. Uchi Mata Preaching the gospel of heel hooks and left kicks

    Joined:
    Jun 21, 2010
    Messages:
    18,578
    Likes Received:
    0
    Location:
    Denver, CO
    Assuming the file is delimited in some way (most likely comma or tab), you need to create a file object, read it line by line, split each line by the delimiter, and then print each item from the array. If you're being asked to create objects with these attributes, you need to define a 'person' class with these objects and then for each line set the attributes of the object to the values contained in the string.

    Make sure you're importing the io library (if you're using a good IDE it will probably be done automatically). I haven't worked with Java in some time but your task sounds like some variant of this.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.