|
| 1 | +package bankaccountquiz; |
| 2 | +import java.util.Date; |
| 3 | +/** |
| 4 | + * |
| 5 | + * @author Ares |
| 6 | + */ |
| 7 | +public class BankAccount { |
| 8 | + |
| 9 | + private long accId; |
| 10 | + private double balance; |
| 11 | + private Date dateCreated; |
| 12 | + private Customer cust; |
| 13 | + private static final String ACCTYPE=""; |
| 14 | + private static int generate_id=10001; |
| 15 | + |
| 16 | + public BankAccount() { |
| 17 | + } |
| 18 | + |
| 19 | + public String getAccType(){ |
| 20 | + return BankAccount.ACCTYPE; |
| 21 | + } |
| 22 | + |
| 23 | + public long getAccId() { |
| 24 | + return accId; |
| 25 | + } |
| 26 | + |
| 27 | + public long genAccountId(){ |
| 28 | + accId=generate_id++; |
| 29 | + return accId; |
| 30 | + } |
| 31 | + |
| 32 | + public double getBalance() { |
| 33 | + return balance; |
| 34 | + } |
| 35 | + |
| 36 | + private void setBalance(double balance) { |
| 37 | + this.balance = balance; |
| 38 | + } |
| 39 | + |
| 40 | + public Date getDateCreated() { |
| 41 | + return dateCreated; |
| 42 | + } |
| 43 | + |
| 44 | + public void setDateCreated(Date dateCreated) { |
| 45 | + this.dateCreated = dateCreated; |
| 46 | + } |
| 47 | + |
| 48 | + public Customer getCust() { |
| 49 | + return cust; |
| 50 | + } |
| 51 | + |
| 52 | + public void setCust(Customer cust) { |
| 53 | + this.cust = cust; |
| 54 | + } |
| 55 | + |
| 56 | + public void deposit(double amount){ |
| 57 | + if(!(amount<0)){ |
| 58 | + this.setBalance(this.getBalance()+amount); |
| 59 | + } |
| 60 | + else{ |
| 61 | + System.err.println("Error from deposit : Amount is less than zero."); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + public void withdraw(double amount){ |
| 66 | + if(!(amount<0 || (amount>this.getBalance()))){ |
| 67 | + this.setBalance(this.getBalance()-amount); |
| 68 | + } |
| 69 | + else{ |
| 70 | + System.err.println("Error from withdraw : Amount is less than zero or amount is greater than your balance."); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + public void transfer(BankAccount target,double amount){ |
| 75 | + if(!(amount<0 || (amount>this.getBalance()))){ |
| 76 | + this.setBalance(this.getBalance()-amount); |
| 77 | + target.deposit(amount); |
| 78 | + } |
| 79 | + else{ |
| 80 | + |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public String toString() { |
| 86 | + return "BankAccount{" + "accId=" + accId + ", balance=" + balance + ", dateCreated=" + dateCreated + ", cust=" + cust + ", ACCTYPE="+BankAccount.ACCTYPE+'}'; |
| 87 | + } |
| 88 | + |
| 89 | + |
| 90 | +} |
0 commit comments