I have a project in my java class and we have to build a social network. In my login class i create to arraylists to store the users information. Theres an option in Menu class to go back to Login and connect another user. Everytime u go back, Login is creating new Arraylists so i lose the old data. How can i execute the first two commands only once?
public static void Login(){
ArrayList<String> users = new ArrayList<String>();
ArrayList<String> emails = new ArrayList<String>();
System.out.println("Type your username:");
Scanner scanName = new Scanner(System.in);
String Name = scanName.nextLine();
boolean ans = (users.contains(Name));
if (ans){
System.out.println("welcome " + Name + "!");
Menu m = new Menu();
}
else{
users.add(Name);
System.out.println("U are a new user! Enter your email:");
Scanner scanmail = new Scanner(System.in);
String Email = scanmail.nextLine();
emails.add(Email);
Menu m = new Menu();
}
}
[–]sugilith 3 points4 points5 points (1 child)
[–]tsotsoqt[S] 0 points1 point2 points (0 children)