• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Sorting Collections

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



pg 549-550 k&B Book

Here's the DVD data that's in the dvdinfo.txt file:
Donnie Darko/sci-fi/Gyllenhall, Jake
Raiders of the Lost Ark/action/Ford, Harrison
2001/sci-fi/??
Caddy Shack/comedy/Murray, Bill
Star Wars/sci-fi/Ford, Harrison
Lost in Translation/comedy/Murray, Bill
Patriot Games/action/Ford, Harrison

I didn't understand the following paragraph

we want to create an instance of DVDInfo
for each line of data we read in from the dvdinfo.txt file. For each instance, we will parse the line of data (remember String.split()?) and populate DVDInfo's three instance variables. Finally, we want to put all of the DVDInfo instances into an ArrayList. Imagine that the populateList() method (below) does all of this. Here is a small piece of code from our application:

ArrayList<DVDInfo> dvdList = new ArrayList<DVDInfo>();
populateList(); // adds the file data to the ArrayList
System.out.println(dvdList);
You might



question:

how does populateList of method looks with necessary coding?
can any one help with coding to understand populateList() method

Thanks
samura
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by samura babu:
...how does populateList of method looks with necessary coding?
can any one help with coding to understand populateList() method...


Coding this method is excellent practice for the exam, because it uses a number of different features. Give it a try, and let us know where you're stuck.

The first step is to just read in each line of the text file. Can you write code for this?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exactly did you not understand? I'll try to write it in different words, I hope that will help:
  • There is a file named "dvdinfo.txt".
  • You have to write a method 'populateList()' that opens the file and reads it line by line.
  • For each line in the file, you create a new DVDInfo object.
  • You initialize each DVDInfo object with the information that you find on each corresponding line.
  • You add each DVDInfo object to an ArrayList of DVDInfo objects.
  • At the end of the method, you return that ArrayList.

  • Some hints:
  • You can use java.io.BufferedReader to read a file line by line (example: Java - Reading text files).
  • As the text suggests, you split the line into separate items (title, genre, actor) by using String.split().
  • Have a look at the Java API documentation of BufferedReader, String.split() and ArrayList.

  • Try writing the code yourself. If you get stuck, then please post what you have written so far and explain where you get stuck.
    [ June 29, 2007: Message edited by: Jesper Young ]
     
    aslika bahini
    Ranch Hand
    Posts: 111
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    successfully done populateList()


    Thanks Jesper Young

     
    I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
    the value of filler advertising in 2021
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic