-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUser.java
More file actions
101 lines (83 loc) · 2.16 KB
/
User.java
File metadata and controls
101 lines (83 loc) · 2.16 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
Abstract class: User.java
Purpose:
- Represents a user in the online shopping system
- Provide common attributes, login/logout, and abstract method: product search
*/
import java.util.HashMap;
public abstract class User {
private String userID;
private String name;
private String phoneNumber;
private String address;
private String password;
private boolean loggedIn;
// Constructor
public User(String userID, String name, String phoneNumber, String address, String password) {
this.userID = userID;
this.name = name;
this.phoneNumber = phoneNumber;
this.address = address;
this.password = password;
}
// Getters and setters
public String getUserID() {
return userID;
}
public String getName() {
return name;
}
public String getPhoneNumber() {
return phoneNumber;
}
public String getAddress() {
return address;
}
public void setPhoneNumber(String newPhoneNumber) {
this.phoneNumber = newPhoneNumber;
}
public void setAddress(String newAddress) {
this.address = newAddress;
}
public void setName(String newName) {
this.name = newName;
}
public void setUserID(String userID) {
this.userID = userID;
}
public void setPassword(String password) {
if (PasswordStrengthTest(password)) {
this.password = password;
}
}
public boolean isLoggedIn() {
return loggedIn;
}
// Login/logout-related methods
public boolean PasswordStrengthTest(String password) {
if (password.length() < 10) {
System.out.println("Password must be at least 10 characters long.");
return false;
}
return true;
}
public boolean login(String userID, String password) {
if (this.userID.equals(userID) && this.password.equals(password)) {
loggedIn = true;
}
return loggedIn;
}
public void logout() {
if (loggedIn) {
System.out.println("User " + userID + " logged out.");
loggedIn = false;
}
}
// Abstract method: searchProducts
public abstract HashMap<String, Product> searchProducts(
String category,
double minPrice,
double maxPrice,
boolean isAvailable,
boolean discountAvailable);
}