Repository navigation
Expand file tree
/
Copy pathAccount.java
More file actions
76 lines (73 loc) · 1.94 KB
/
Copy pathAccount.java
File metadata and controls
76 lines (73 loc) · 1.94 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
import org.json.JSONException;
import java.io.IOException;
public class Account {
private final String userId;
private String userName;
private String password;
private double balance;
public String generateId() {
final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
String s="";
for(int i=0;i<4;i++) {
int num=(int)(Math.random()*62);
char ch=AB.charAt(num);
s+=ch;
}
return "ID" + s;
}
public String getPassword() {
return password;
}
public Account(String userName,String password,double balance) {
this.userId=generateId();
this.userName=userName;
this.password=password;
this.balance=balance;
}
public Account(String userId,String password) {
this.userId=userId;
this.userName="";
this.password=password;
this.balance=0;
}
public Account(String userId,String userName,String password,double balance) {
this.userId=userId;
this.userName=userName;
this.password=password;
this.balance=balance;
}
public Account(String userId){
this.userId = userId;
}
public String getUserId() {
return this.userId;
}
public String getUserName() {
return this.userName;
}
public double getBalance() throws JSONException {
return this.balance;
}
//This method adds sales amount to user bank account
//public void addMoney(double amt) throws JSONException, IOException {
// balance+=amt;
// System.out.println("Transaction Successful");
// System.out.println(String.format("%.2f",amt)+"credited to your account");
//}
// This method deducts purchase amount from user bank account after ensuring enough bank balance
//public boolean deductMoney(double amt)
//{
// if(amt<=balance)
// {
// balance-=amt;
// System.out.println("Transaction Successful");
// System.out.println(String.format("%.2f",amt)+"debited from your account");
// return true;
// }
// else
// {
// System.out.println("Transaction Unsuccessful due to shortage of money in your account");
// return false;
// }
//}
}