-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUser.java
185 lines (148 loc) · 4.69 KB
/
User.java
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import java.util.*;
import java.time.*;
class User {
String username;
String fullName;
String phoneNumber;
String nationalId;
Double balance;
String password;
String email;
ArrayList<Ticket> tickets= new ArrayList<Ticket>();
ArrayList<Transaction> transactions = new ArrayList<Transaction>();
/*public void changePassword(String oldPass, String newPass1, String newPass2) throws passwordsDoNotMatchException {
if (oldPass.equals(passwords.get(index))) {
if (newPass1.equals(newPass2)) {
passwords.set(index, newPass1);
} else
throw new passwordsDoNotMatchException();
} else throw new passwordsDoNotMatchException(); //?
}
public void changeUsername(String newUser) {
if (isLoggedIn) {
int index = findUser(currentUser);
users.set(index, newUser);
}
}
*/
public void changePhoneNumber(String newNum) {
setPhoneNumber(newNum);
}
public void changeFullName(String newName) {
setFullName(newName);
}
public void changeEmail(String newEmail) {
setEmail(newEmail);
}
public void changeNationalID(String newId) {
setNationalId(newId);
}
public void addBalance(Double amount) {
balance += amount;
Transaction t = new Transaction();
Date d = new Date();
LocalDateTime ldt = LocalDateTime.now();
String dateTime = ldt.toString();
int index = dateTime.indexOf('T');
String date = dateTime.substring(0, index - 1);
String time = dateTime.substring(index, dateTime.length() - 1);
d.setDate(date);
d.setTime(time);
t.setDate(d);
t.setId("1234"); //?
t.setPrice(amount);
t.setType("Charge increase");
transactions.add(t);
}
public void removeBalance(Double amount) {
balance -= amount;
Transaction t = new Transaction();
Date d = new Date();
LocalDateTime ldt = LocalDateTime.now();
String dateTime = ldt.toString();
int index = dateTime.indexOf('T');
String date = dateTime.substring(0, index - 1);
String time = dateTime.substring(index, dateTime.length() - 1);
d.setDate(date);
d.setTime(time);
t.setDate(d);
t.setId("1234"); //?
t.setPrice(amount);
t.setType("Charge reduction");
transactions.add(t);
}
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return this.username;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getFullName() {
return this.fullName;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getPhoneNumber() {
return this.phoneNumber;
}
public void setNationalId(String nationalId) {
this.nationalId = nationalId;
}
public String getNationalId() {
return this.nationalId;
}
public void setBalance(Double balance) {
this.balance = balance;
}
public Double getBalance() {
return this.balance;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return this.password;
}
public void setEmail(String email) {
this.email = email;
}
public String getEmail() {
return this.email;
}
// public void setTickets(Ticket[] bookedTickets) {
// this.tickets = bookedTickets;
// }
public void addTicket(Ticket ticket) {
this.tickets.add(ticket);
}
public Ticket[] getTickets() {
Ticket[] result = new Ticket[this.tickets.size()];
result = this.tickets.toArray(result);
return result;
}
/*class wrongPasswordException extends Exception {
wrongPasswordException() {
}
String msg = "Wrong Password";
}
class userDoesNotExistException extends Exception {
userDoesNotExistException() {
String msg = "The username is incorrect.";
}
}
class usernameAlreadyExistsException extends Exception {
usernameAlreadyExistsException() {
}
String msg = "This username already exists. please pick another one.";
}
class passwordsDoNotMatchException extends Exception {
passwordsDoNotMatchException() {
}
String msg = "Passwords do not match. Please try again.";
}
*/
}