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...
import java.util.ArrayList;
import java.util.Scanner;
public class Enrolment
{
Scanner scanner = new Scanner(System.in);
private ArrayList<Unit> units;
public Enrolment()
{
units = new ArrayList<Unit>();
}
and here is the code from where I actually create the unit once I have the information from the user...
Unit 1005 = new Unit(name,code,sem1,sem2);
units.add(1005);
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 code = new Unit(....)
but obviously that just created it called 'code'.
Just wandering what ways are their of making this change everytime a new instance is created.
Thanks for your help