forked from loopccoew/Buffer_2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccounts.java
More file actions
63 lines (57 loc) · 1.58 KB
/
Accounts.java
File metadata and controls
63 lines (57 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package railways;
import java.util.*;
public class Accounts {
LinkedList<User>userList=new LinkedList<>();
Scanner sc=new Scanner(System.in);
void createAccount() {
int flag=0;
do{
flag=0;
System.out.print("\n\tEnter the username you want to use for your account: ");
String userName = sc.nextLine();
for(User u : userList) {
if(u.userName.equals(userName)) {
System.out.println("\tAlready exists. Try a new username.");
flag=1;
break;
}
}
if(flag==0){
System.out.print("\n\tEnter the password to secure your account: ");
String password = sc.nextLine();
User u1 = new User(userName,password);
userList.add(u1);
System.out.println("\n\tAccount created successfully!!");
u1.userMenu();
}
}while(flag==1);
}
public void login() {
int flag=0, trying=0;
do{
System.out.print("\n\tEnter the userName: ");
String userName=sc.nextLine();
System.out.print("\n\tEnter the password: ");
String password=sc.nextLine();
User u1 = null;
for(User u:userList) {
if(u.userName.equals(userName) && u.password.equals(password) ){
flag=1;
u1=u;
break;
}
}
if(flag==1) {
System.out.println("\n\tLogin Successful!!");
u1.userMenu();
}
else {
System.out.println("\tPlease enter proper credentials.\n");
System.out.println("\tDo you want to keep trying?\n\t1.Yes\n\t2.Exit");
System.out.print("\n\tEnter your choice: ");
trying = sc.nextInt();
sc.nextLine();
}
}while(flag==0 && trying==1);
}
}