-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAccount.java
More file actions
199 lines (165 loc) · 5.31 KB
/
Account.java
File metadata and controls
199 lines (165 loc) · 5.31 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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author shahad
*/
public class Account {
ArrayList<Account> existAccount= new ArrayList<Account>();
protected String username ;
protected String name ;
protected String password ;
protected String phone_no;
protected String address;
private Shoppingcart shoppingCart=new Shoppingcart();
public static int numOfAccount;
public boolean validPass()
{
//return true if and only if password:
//1. have at least eight characters.
//2. consists of only letters and digits.
//3. must contain at least two digits.
if (password.length() < 8) {
return false;
} else {
char c;
int count = 1;
for (int i = 0; i < password.length() - 1; i++) {
c = password.charAt(i);
if (!Character.isLetterOrDigit(c)) {
return false;
} else if (Character.isDigit(c)) {
count++;
if (count < 2) {
return false;
}
}
}
}
return true;
}
public boolean ValidUsername()
{
//return true if and only if Username:
//1. start with characters
//2. Number of characters must be between 8 to 15.
Pattern unPattern = Pattern.compile("^[a-zA-Z0-9.!@#$%^&*-_]{8,15}$");
Matcher unMatcher = unPattern.matcher(username);
if(unMatcher.matches()){
return true;
} else {
return false;
}
}
public boolean SignUp(){
if(ValidUsername()&& validPass()){
System.out.println("You have been signed up successfully");
return true;
}
else{
System.out.println("Incorrect username or password, try again ");
return false;
}
}
public boolean validateLogin(Account acc){
Scanner input=new Scanner(System.in);
System.out.println("Enter username :");
String inpUsername=input.next();
System.out.println("Enter password :");
String inpPass=input.next();
if(acc.username.equals(inpUsername)&&acc.password.equals(inpPass)){
if(acc.SignUp()==true)
System.out.print("Welcome "+acc.name);
return true;
}
else{
System.out.println("You need to sign up first");
return false;}
}
public void displayCart(Account cus){
if(cus instanceof Customer){
System.out.print("Chosen Payment Method :");
if(cus.shoppingCart.getPaymentMethod()==1){
System.out.println("Cash");
}
if(cus.shoppingCart.getPaymentMethod()==2){
System.out.println("Credit");
}
System.out.println("*****************************");
System.out.print("Student Discount: ");
if(cus.shoppingCart.getIfStudent()==true){
System.out.println("Applicable");
}
else{
System.out.print("Not Applicable");
System.out.println(" ");}
System.out.println("*****************************");
System.out.print("Delivary: ");
if(cus.shoppingCart.getDeliverReq()==true){
System.out.println("Requested");
System.out.println("Delivary pin:"+cus.shoppingCart.getDeliveryPin());
}
System.out.println("*****************************");
System.out.println("Total Price:"+cus.shoppingCart.getTotalPrice());
}
else
System.out.println("This feature is only for customers ");
}
// constructors, setters and getters
public Account() {
}
public Account(String username, String name, String password, String phone_no, String address) {
this.username = username;
this.name = name;
this.password = password;
this.phone_no = phone_no;
this.address = address;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPhone_no() {
return phone_no;
}
public void setPhone_no(String phone_no) {
this.phone_no = phone_no;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Shoppingcart getCart(){
return shoppingCart;
}
public void setCart(int paymentMethod, boolean ifStudent, boolean newdeliverReq, int newdeliverPin,double newtotalPrice){
int pa=paymentMethod;
boolean ifS=ifStudent;
boolean delR=newdeliverReq;
int delp=newdeliverPin;
double total=newtotalPrice;
shoppingCart.setPaymentMethod(pa);
shoppingCart.setIfStudent(ifS);
shoppingCart.setDeliverReq(delR);
shoppingCart.setDeliveryPin(delp);
shoppingCart.setTotalPrice(total);
}
}