How should I add a whole class in a linked list that also has arguments such as name, password and a boolean to check if it's connected to a server?
The strange thing about this issue is that the User is successfully registered in the User.java
, but not in the UserRegistery.java
.
public class User {
private String name = "";
private String password = "";
private String email = "";
private boolean connection;
public User(String name, String password, boolean connection){
this.name = name;
this.password = password;
this.connection = connection;
setUserName(name);
setUserPassword(password);
setUserConnection(connection);
System.out.println("Client Created : User ["+format()+"]");
}
public void setUserName(String name){
this.name = name;
}
public String getUserName(){
return name;
}
public void setUserPassword(String password){
this.password = password;
}
public String getUserPassword(){
return password;
}
public void setUserEmail(String email){
this.email = email;
}
public String getUserEmail(){
return email;
}
public void setUserConnection(boolean connection){
this.connection = connection;
}
public boolean getUserConnection(){
return connection;
}
public String format(){
return String.format("%-5s, %-5s, %s" , getUserName(),
getUserPassword(), getUserConnection());
}
}
public class UserRegistry {
private LinkedList<User> users;
private User user;
private String name = "", password = "";
private boolean conn = false;
//Constructor:
public UserRegistry() { //Setting new students in the Linked List
users = new LinkedList<User>();
}
public void addUser(User aUser) {
System.out.println("Waiting to "
+ "add user to the server . . . ");
users.add(aUser);
System.out.println("Client Creation "
+ ": Confirmed !!! ");
System.out.println("Client Creation "
+ ": Declined !!! ");
}
}
This is the output I get: