hashmap question

hi guys. i am creating a program in which teachers are going to enter the grades for each student and then it will be stored in a file. i am doing this because i am bored and need to pass some time till my Gf arrive to give me some some. so i thought to write a Java program.

i am using hashmap in order to store all the student name, int id, char grade. i was curious if there is a way that when i try to retrieve the studentList with their name, id and grade from a text file should all be sorted alphabetically by their name. it will be good if i had an option of entering the first name and lastname but i combined both of them in name.

Guidance needed. i know about comparable interface and tried to implement it but give me errors.

Thankyou

[772 byte] By [lrngjavaa] at [2007-11-27 2:23:58]
# 1

> Guidance needed. i know about comparable interface and tried to implement it but give me errors.

public class Foo implements Comparable < Foo > {

public int compareTo(Foo that) {

...

}

}

DrLaszloJamfa at 2007-7-12 2:30:15 > top of Java-index,Java Essentials,Java Programming...
# 2
i found a better way. dump the map into treemap :)
lrngjavaa at 2007-7-12 2:30:15 > top of Java-index,Java Essentials,Java Programming...
# 3

> hi guys. i am creating a program in which teachers

> are going to enter the grades for each student and

> then it will be stored in a file. i am doing this

> because i am bored and need to pass some time till my

> Gf arrive to give me some some. so i thought to write

> a Java program.

>

> i am using hashmap in order to store all the student

> name, int id, char grade. i was curious if there is a

> way that when i try to retrieve the studentList with

> their name, id and grade from a text file should all

> be sorted alphabetically by their name. it will be

> good if i had an option of entering the first name

> and lastname but i combined both of them in name.

>

> Guidance needed. i know about comparable interface

> and tried to implement it but give me errors.

>

> Thankyou

If you want to store the entries in some sort of order, how about a using a sorted map like a tree map?

guitar_man_Fa at 2007-7-12 2:30:15 > top of Java-index,Java Essentials,Java Programming...
# 4
> If you want to store the entries in some sort of> order, how about a using a sorted map like a tree> map?... too slow...
guitar_man_Fa at 2007-7-12 2:30:15 > top of Java-index,Java Essentials,Java Programming...
# 5

question.

as i have stated before that i am using Hashmap in order to add students remove students etc...

i was wondering if there is a way to save the Student objects in a text file rather than using serializable since the output in the text file will be in a binary format. i would like it to be readable by a human while opening the text file.

bottom line can i save my student objects in a file in a human readable form?

lrngjavaa at 2007-7-12 2:30:15 > top of Java-index,Java Essentials,Java Programming...
# 6

> question.

>

> as i have stated before that i am using Hashmap in

> order to add students remove students etc...

>

> i was wondering if there is a way to save the Student

> objects in a text file rather than using serializable

> since the output in the text file will be in a binary

> format. i would like it to be readable by a human

> while opening the text file.

>

> bottom line can i save my student objects in a file

> in a human readable form?

Absolutely. You will probably have to write custom code to do it, though.

- Adam

guitar_man_Fa at 2007-7-12 2:30:15 > top of Java-index,Java Essentials,Java Programming...
# 7
custom coding means alot of usage of String and StringBuffer methods like indexOf, substring, etc...?
lrngjavaa at 2007-7-12 2:30:15 > top of Java-index,Java Essentials,Java Programming...
# 8
maybe, but I would tend to look more into printf, Formatter, and Scanner. These will help you read and write the file easier.- Adam
guitar_man_Fa at 2007-7-12 2:30:15 > top of Java-index,Java Essentials,Java Programming...
# 9
Mr Adam. Thankyou. if i fall in any trouble i will post back and may be you can come and rescue me with this custom coding ? :)
lrngjavaa at 2007-7-12 2:30:15 > top of Java-index,Java Essentials,Java Programming...
# 10
I'll help you out if I'm online, but I don't make a point of staying on 24-7. American Idol is on soon ;)I'm sure there are others here who can help out too, if you get stuck.- Adam
guitar_man_Fa at 2007-7-12 2:30:15 > top of Java-index,Java Essentials,Java Programming...
# 11
lol no wonder your nickname also define your personality and why you like american idol :).Thanks though
lrngjavaa at 2007-7-12 2:30:15 > top of Java-index,Java Essentials,Java Programming...