-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserManager.java
More file actions
54 lines (38 loc) · 953 Bytes
/
UserManager.java
File metadata and controls
54 lines (38 loc) · 953 Bytes
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
import java.util.HashMap;
import java.util.Scanner;
/**
* Created by alex on 07/12/2016.
*/
public class UserManager {
/**
* Singleton
*/
private static UserManager userManager = new UserManager();
private UserManager() {
}
public static UserManager getInstance() {
return userManager;
}
private static HashMap<Integer, User> users = new HashMap<>();
private static int currentId = 0;
public int countUsers() {
return users.size();
}
public void addUser() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter username for new user: ");
String userName = scanner.nextLine();
User user = new User(userName);
users.put(currentId, user);
System.out.println("Added new user " + userName);
currentId++;
}
public User getUserById(Integer id) {
return users.get(id);
}
public void printAllUsers() {
users.forEach((k,v) -> {
System.out.println("[" + k + "]" + " \t " + v);
});
}
}