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]

> 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) {
...
}
}
i found a better way. dump the map into treemap :)
> 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?
> 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...
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?
> 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
custom coding means alot of usage of String and StringBuffer methods like indexOf, substring, etc...?
maybe, but I would tend to look more into printf, Formatter, and Scanner. These will help you read and write the file easier.- Adam
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 ? :)
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
lol no wonder your nickname also define your personality and why you like american idol :).Thanks though