H:\CSC120\Java\lec15\src\BankAccount.java
 1 /*
 2  * To change this license header, choose License Headers in Project Properties.
 3  * To change this template file, choose Tools | Templates
 4  * and open the template in the editor.
 5  */
 6 
 7 /**
 8  *
 9  * @author cindricbb
10  */
11 public class BankAccount {
12     
13     //property declarations
14     
15     private String idNum, name;
16     private Double balance;
17     
18     // constructors
19     
20     public BankAccount(String num, String n, Double initBal) {
21         idNum = num;
22         name = n;
23         balance = initBal;
24     } // end of 3-parameter constructor
25     
26     // getters
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     // setters
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     // other methods
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     }  // end of makeADeposit
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         } // end if
81         else {
82             System.out.println("Hey " + name + ", you can't withdraw $" + withdrawalAmt
83                    + "!!!  You only have a balance of $" + balance);
84         } // end else
85     }  // end of makeAWithdrawal
86     
87     
88 } // end of class BankAccount
89