Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read the records from the ArrayList

 
Mg Oo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Java masters,

I'm facing some difficulties with a java quizz.
Please give me some ideas.


--------------------------------------------------
Quiz01 :

The text file has three records like :

John
NO.123, HirLet Road,LL 234
025-5-5455
1 5 0 2 7000
Paul
NO.23, Hello Road,LL 235
025-5-5454
1 5 0 2 6000
Mary
NO.23, Mine Road,LL 235
23-5-5454
1 5 0 2 9000



According to the above info, we know the file has John's related record and Paul's related one, and Mary's related one.7000,6000 and 9000 are their respective salaries.

For each record,create an object and add it to ArrayList.
Having created all objects, write those objects to a binary where those whose salaries are over 6000.

Again, display the name of them.

-----------------------------------------------



For the above,


� Do I have to implement StringTokenizer() to make apart each person ?
If so,how ? I guess each record span four lines. So I cut out four lines for each record ?

� How can I compare their salaries ?
To do so,I think I have to use StringTokenizer again.
 
Campbell Ritchie
Sheriff
Posts: 48917
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use StringTokenizer, althought that is now deprecated.

Why not use a java.util.Scanner to read and parse the lines and data from the files?
You did say they are simple text files, didn't you?

I have never used a Comparator, but you can probably get it to produce a compare() method which works on salaries, then you can use a method like sort() in the java.util.Arrays class or the java.util.ArrayList class.

And if you win the quiz, can I share the prize?

CR
 
Mg Oo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.

Just a quizz in a school textbook
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic