-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountManger.java
More file actions
65 lines (55 loc) · 1.82 KB
/
Copy pathAccountManger.java
File metadata and controls
65 lines (55 loc) · 1.82 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
import java.io.Serializable;
public class AccountManger implements Serializable {
private static final long serialVersionUID = 1L;
// Store user pin, account name
private String firstName;
private String lastName;
private String password;
private String accountNumber;
private double balance;
// Random array of unused account numbers that are signed to new customers
public AccountManger(String firstName, String lastName, String password, String accountNumber){
this.firstName = firstName;
this.lastName = lastName;
this.password = password;
this.accountNumber = accountNumber;
this.balance = 0;
}
@Override
public String toString() {
//Account info
return "\nAccount Info:\nAccount Name: " + getFirstName() +" " + getLastName() + "\nPassword: " + getPassword() + " \nPin: " + getAccountPin(this.accountNumber);
}
public String getFirstName() {
return firstName;
}
public String getAccountPin(String accountNumber){
String[] number = accountNumber.split(" ");
// last four digits of the account
return number[3];
}
public String getLastName() {
return lastName;
}
public String getPassword() {
return password;
}
public String getAccountNumber() {
return accountNumber;
}
public double getBalance(){
return balance;
}
public void setBalance(double amount){
this.balance += amount;
}
public void withdraw(double amount){
if(this.balance > amount){
this.balance -= amount;
}
else{
// If User doesn't have enough in account balance
System.out.println("Transaction failed: Insufficient balance. Your current balance is " + getBalance());
}
}
}