-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.java
More file actions
38 lines (31 loc) · 1009 Bytes
/
Copy pathUser.java
File metadata and controls
38 lines (31 loc) · 1009 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
import java.util.ArrayList;
public class User {
private String Cus_name;
private String username;
private int no_of_purchases = 0;
public static ArrayList <User> list_of_users = new ArrayList<>();
public User(String Cus_name, String username){
this.Cus_name = Cus_name;
this.username = username;
}
public String getUsername() {
return this.username;
}
public int getNo_of_purchases() {
return this.no_of_purchases;
}
public void setNo_of_purchases() {
this.no_of_purchases = this.no_of_purchases + 1 ;
}
public static void addUsertoList(User user) {
boolean userExists = false;
for (int i = 0; i < list_of_users.size(); i++) {
if (user.getUsername().equals(list_of_users.get(i).getUsername())) {
System.out.println("User already exists");
userExists = true;
}else{
list_of_users.add(user);
}
}
}
}