Not so last min, last min uni work, Programing and UML

Phil99 said:
Looks like you forgot to tell the HashMap what types of variables to expect (look up Generics for more info)

Code:
HashMap[b]<Integer,Test>[/b] hashmap = new HashMap[b]<Integer,Test>[/b]();

You also need to pass the object you want to be stored with relation to the key you're supplying to the put() method as well otherwise you're just trying to store a key with nothing actually linked to it.

The bits in the < > tell it what to expect; the first (Integer) is the type of object the key should be and the second is the type the value you want it to return when you look up the key should be.

With the HashMap above the method signature for the put method in the HashMap object would look something like this:

Code:
public void put(int key, Test value)

If that helps to explain it at all.

The API explains more: http://java.sun.com/j2se/1.4.2/docs/api/java/util/HashMap.html
Yes, but HashMap<Integer,Test> hashmap = new HashMap<Integer,Test>(); = error: Not a statement
 
Thats the correct syntax where abouts are you defining it?

Generics was only added to java 1.5... if you have version <1.5 it won't work and stop using blue-j it's bloody horrible :p
 
Last edited:
Una said:
Thats the correct syntax where abouts are you defining it?

Generics was only added to java 1.5... if you have version <1.5 it won't work and stop using blue-j it's bloody horrible :p

Well I would stop using it, but uni seem to love it
 
jcb33 said:
and each time I run this I could add it automaticaly to a hashmap, so say the first time I run, customer number = 1, second, 2 etc?
The only way I can think of to make it add an auto increment ID to each object, is to keep an int in your control class which keeps the most recently generated id, and then each time you create a new CustomerRecord instance pass the value of this int plus 1 to the constructor.

With regards to your address, it is totally up to you. You could store the whole thing as a String, or create a new Address class which had fields like
Code:
int number;
String road;
String town;
String county;
String postcode;
etc, and then store a reference to an Address instance in your CustomerRecord instance. I would be tempted to do it the second way, as then you could do searches on the customer database based on specifics of the address.

Lastly, as already suggested it seems as though you may be using JDK 1.4.2 or lower. To use Generics (the <Integer, Test> bit) you need 1.5 or above :)
 
jcb33 said:
Well I would stop using it, but uni seem to love it
Best way to learn a language is to do it all by hand in a plain text editor. Once you have grasped the syntax etc then start using something like Eclipse to make your life easier. No point in using something that auto completes code if you don't know what it's writing whilst completing :)

Text editor I use is called jEdit. It's very good and and free!
 
Amoeba said:
The only way I can think of to make it add an auto increment ID to each object, is to keep an int in your control class which keeps the most recently generated id, and then each time you create a new CustomerRecord instance pass the value of this int plus 1 to the constructor.

With regards to your address, it is totally up to you. You could store the whole thing as a String, or create a new Address class which had fields like
Code:
int number;
String road;
String town;
String county;
String postcode;
etc, and then store a reference to an Address instance in your CustomerRecord instance. I would be tempted to do it the second way, as then you could do searches on the customer database based on specifics of the address.

Lastly, as already suggested it seems as though you may be using JDK 1.4.2 or lower. To use Generics (the <Integer, Test> bit) you need 1.5 or above :)
Thanks, will try to get the latest java tomorow (Bed early as work in morning) and im not sure that searching the database will be an issue, as I have no idea how to do that at all, and we have not even discused this in lectures workshops :eek: Whats even more scary is we are going from basic java this year, to programing graphics in C++ next year, and thats things like how light reflects off a surface :/
 
Even if you don't need to perform searches etc now, it's always best to plan ahead! Plus it may get you extra marks if you have a nice OO design, and have planned extensibility :).
 
Amoeba said:
Even if you don't need to perform searches etc now, it's always best to plan ahead! Plus it may get you extra marks if you have a nice OO design, and have planned extensibility :).
Could I be cheeky and ask you if you would mind looking over what I have done, and letting me know if its correct? Have just for now created a system that can have one of each vehicle, and 1 customer at any one time
 
Thanks, have sent you the files in a rar file to the email in your trust :) Should be 32kb

*EDIT* Well as that did not work, I have uploaded it to my host and will email you the link, said your email blacklisted me for sending a rar file!
 
Last edited:
Just incase you already downloaded it from the link I sent you, I have updated it since then, its not yet commented though, gonna be doing that today (I know I should comment as I go but I find it easier to do it after I finish)
 
Why not post it up on here? This is a forum, not jcb33's personal help pages. It might be beneficial for other people to see what people are doing to the code to further their knowledge of it as well :)
 
Phil99 said:
Why not post it up on here? This is a forum, not jcb33's personal help pages. It might be beneficial for other people to see what people are doing to the code to further their knowledge of it as well :)
Dont be rude :p, The reason im not posting it, as noted before, there are other people from my uni that use these forums, and the uni searches the net for code, so if i post my code, they could find it and say I plagerised myself...

I am quite happy however to post code from my other assignments :)
 
5ingh said:
You are already plagerising by posting up your diagrams and asking for 'more' than help :)
Depends how you define plagerism, my diagrams have changed since then (As my program looked nothing like them) And I have not copied anything from this topic, wrote my hole program alone actualy, wheter its done right or not thought is another kettle of fish :eek:
 
Back
Top Bottom