public class Start {
public Register theReg = new Register();
public static Start go = new Start();
public static void main(String[] args) {
Register theReg = new Register();
go.regUsers();
if(theReg.logIn("jsmith","password")) {
System.out.println("You're logged in as " +
theReg.userLoggedIn.getName());
} else {
System.out.println("dang");
}
}
public void regUsers() {
Student regJoe =
theReg.regSeniorStaff("Joe smith", "password", "jsmith", 1);
}
}
public class Register {
public ArrayList<People> users;
public People userLoggedIn;
public Register () {
users = new ArrayList<People>();
users.add(new Student("john","password","jo",1));
userLoggedIn = null;
}
public Student regStudent(String name, String password,
String username, int stuId) {
Student s = new Student(name, password, username, stuId);
users.add(s);
return s;
}
}
I'm thinking I've just missed out something silly. Like....
The start methods will create a new Register
object, which has its ArrayList
. Then a bit down the line it starts registering users using the methods like regStudent
. But, only the constructor on Register
lets me add objects to the ArrayList
; calling the methods to do the same thing later on just doesn't add them. It creates the object but can't add them. Also can't remove things, only .get
works in them.
Any help would be great, thanks!