-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.java
More file actions
37 lines (29 loc) · 939 Bytes
/
Copy pathDatabase.java
File metadata and controls
37 lines (29 loc) · 939 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
package com.usermanagement;
import java.util.HashMap;
import java.util.Map;
public class Database {
private Map<String, User> userTable;
public Database() {
this.userTable = new HashMap<>();
}
// Method to add a new user to the database
public void addUser(User user) {
userTable.put(user.getUsername(), user);
}
// Method to delete a user from the database by username
public void deleteUser(String username) {
userTable.remove(username);
}
// Method to get a user from the database by username
public User getUser(String username) {
return userTable.get(username);
}
// Method to update a user in the database
public void updateUser(User user) {
userTable.put(user.getUsername(), user);
}
// Method to list all users in the database
public Map<String, User> listUsers() {
return new HashMap<>(userTable);
}
}