object instantiation and arrayList
Hi. I am reasonably new to Java but know the basics. I am just wandering if i could get some small help...
I am creating an Enrolment System for a University (its my assignment) and I have a class called Unit, and a class called Enrolment. In the Enrolment class, I am writing a method for the user to create a new Unit, but I have the following problem, which might be hard to explain.
Here is some of the code from the top...
and here is the code from where I actually create the unit once I have the information from the user...
public class Enrolment
Scanner scanner = new Scanner(System.in);
private ArrayList<Unit> units;
units = new ArrayList<Unit>();
My question is... where it says '1005' (the name of the instance of Unit that I create)... is their a way so that it will change with every new unit? Perhaps so it will be the name of a variable, such as 'code'?? I tryed something like...
Unit 1005 = new Unit(name,code,sem1,sem2);
but obviously that just created it called 'code'.
Unit code = new Unit(....)
Just wandering what ways are their of making this change everytime a new instance is created.
Thanks for your help