473,505 Members | 13,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

java program: urgent

1 New Member
hello
In my assignment we asked to create classes like student, grade, semester, course
all of them have constructors & methods.
We have to create hashmap that contains key as student id & object of studentRecord(another class which contains student data)
then we have to create treeset of grades in the student record so that all the grades will be sorted by semester wise.
I am not able to create a treeset because it accept the grade as raw type when I did tht I can't call the iterator
Set<Grade> t = new TreeSet<Grade>();
t.add(g1)
Iterator <key>i = m.iterator<key>(); -> asks for expression.
I created the generic method printmap like the following
public <key> void printSet(key g, TreeSet<key> m)
{
m.add(g);
System.out.println("TreeSet of Grades: ");
Iterator <key>i = m.iterator<key>();
}
}

In the class called StudentDatabase [contains main() ] hashmap is created <string, studentRecord> then its printed
then I want to call a method printSet to print treeset

SO how to use iterator of reference or raw types (like Object)
please reply soon, it's urgent
Feb 16 '08 #1
1 1227
Laharl
849 Recognized Expert Contributor
Does the grade class implement the Comparable interface? If not, you need to since TreeSet/TreeMap both use compareTo to sort. For the HashMaps, make sure you write hashCode() and equals() methods since those are how the HashMap sorts. More information on the latter two is available in the Howtos section (this is important), and the API has full information all 3.
Feb 16 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
6886
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on...
4
2126
by: mohana | last post by:
hi, i just want 2 communicate with the near by computer. i got this program from internet. i have two programs called Server.java and Client.java. i am putting that program here now, Server.java...
6
27678
by: gauravkhanna | last post by:
import java.io.*; class Automation1 implements Runnable { int iterationCount=0; Thread t; FileReader fr; //FileWriter fw; BufferedReader br; ...
1
2290
by: satish mullapudi | last post by:
Hi, I am using DB2 v8.2 & jdk 1.4. 1. I have a java program which returns an array which contains 1 to 5 numbers. The code: public class ArrayTest { public static final int ARRAY_SIZE = 5;...
24
7358
by: crazystone82 | last post by:
Hi all, please send me a source code to transfer a file to a server running on another pc in the LAN...using JAVA .By getting the source path and destination path through textfield implemented...
3
1273
by: joshwa | last post by:
i need java program for moving the first line from several word documents to one document, could any one there to help me, its very urgent
5
2716
by: Ananthu | last post by:
Hi I have done all the codings part for connecting mysql server with java application but when i try to compile,the compilation is successful and during execution i get the following message, ...
2
1481
by: toprahman | last post by:
Hi guys, I'm a student teacher at a high school in Washington D.C. and I've come across a slight problem. See, I'm a math major, but one of the computer science teachers just quit and they need me to...
9
1607
by: uppili4chi | last post by:
Good morning my dear friends, I am uppili from India. i am working in one mnc. I need a help very urgent. "My problem i need to write a program for search a file just like search option at...
1
2072
by: javabeginner123 | last post by:
i have a java prob, and i have to solve it fast, but i'm just getting to know it, so plz help me solve it with full code completed, thanks so much. the prob is to create a monter fight and there is...
0
7213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.