-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserServices.java
More file actions
64 lines (46 loc) · 1.38 KB
/
Copy pathUserServices.java
File metadata and controls
64 lines (46 loc) · 1.38 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
64
import java.util.Scanner;
import java.util.ArrayList;
public class UserServices{
private static Scanner input = new Scanner (System.in);
private static ArrayList <User> userList = new ArrayList<>();
private User loggedInUser;
public void signUp(){
System.out.println("Enter first name: ");
String firstName = input.nextLine();
System.out.println("Enter last name: ");
String lastName = input.nextLine();
System.out.println("Enter age: ");
int age = input.nextInt();
System.out.println("Enter email address: ");
String email = input.nextLine();
System.out.println("Enter password: ");
String password = input.nextLine();
User user = new User();
user.setFirstName(firstName);
user.setLastName(lastName);
user.setAge(age);
user.setEmailAddress(email);
user.setPassword(password);
userList.add(user);
}
public boolean login(){
System.out.println("Enter email address: ");
String email = input.nextLine();
System.out.println("Enter password: ");
String password = input.nextLine();
for (User user : userList){
if (user.getEmailAddress().equalsIgnoreCase(email) && user.getPassword().equals(password)){
loggedInUser = user;
break;
}
}
if (loggedInUser == null){
System.out.println("Invalid email or password");
return false;
}
else{
System.out.printf("Welcome %s%n", loggedInUser.getFirstName());
return true;
}
}
}