H:\CSC120\Java\lec15\src\BankAccount.java |
1
2
3
4
5
6
7
8
9 @author
10
11 public class BankAccount {
12
13
14
15 private String idNum, name;
16 private Double balance;
17
18
19
20 public BankAccount(String num, String n, Double initBal) {
21 idNum = num;
22 name = n;
23 balance = initBal;
24 }
25
26
27
28 public String getIdNum() {
29 return idNum;
30 }
31
32 public String getName() {
33 return name;
34 }
35
36 public Double getBalance() {
37 return balance;
38 }
39
40
41
42 public void setIdNum(String num) {
43 idNum = num;
44 }
45
46 public void setName(String n) {
47 name = n;
48 }
49
50 public void setBalance(Double bal) {
51 balance = bal;
52 }
53
54
55
56 public String toString() {
57 return name + " owns account number " + idNum
58 + ", which has a balance of $" + balance;
59 }
60
61
62 public void makeADeposit( Double depositAmt ) {
63
64 balance = balance + depositAmt;
65 System.out.println(name + " deposited $" + depositAmt + " into her/his account");
66
67 }
68
69
70 public void makeAWithdrawal( Double withdrawalAmt ) {
71
72 if (balance >= withdrawalAmt) {
73 balance = balance - withdrawalAmt;
74 System.out.println(name + " withdrew $" + withdrawalAmt + " from her/his account");
75
76 if (balance == 0) {
77 System.out.println(" that reduces the balance in the account to $0");
78 }
79
80 }
81 else {
82 System.out.println("Hey " + name + ", you can't withdraw $" + withdrawalAmt
83 + "!!! You only have a balance of $" + balance);
84 }
85 }
86
87
88 }
89