-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccount.java
More file actions
104 lines (76 loc) · 2.19 KB
/
BankAccount.java
File metadata and controls
104 lines (76 loc) · 2.19 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* Class Name: The BankAccount class - Base/Super class
Use in Inheritance Discussion/Assignment
Author: P Baker
Date :
Brief Description: A Basic BankAccount class/blueprint
*/
package ch12;
import java.text.NumberFormat;
class BankAccount
{
protected int acctNumber; //changed from private to protected to give hierarchy access
protected double balance;
protected String name;
private static int acctCount= 0; //not an instance variable, but a class variable (static)
/** constructs a bank account with zero balance, zero account number
and name set to Unknown
*/
public BankAccount() {
acctNumber = 0;
balance = 0.0;
name = "Unknown";
acctCount++; //increment when object created
}
/*
constructs a bank account with an account number, an initial balance, and
an owner!
*/
public BankAccount(int acctNo, double initBalance, String owner) {
acctNumber = acctNo;
balance = initBalance;
name = owner;
acctCount++; //increment when object created
}
//all of the mutator methods - set
public void setAcctNumber(int acct)
{
acctNumber = acct;
}
//DO NOT IMPLEMENT setBalance. Don't want accounts
//to be able to set a balance. Use deposit or withdraw methods
public void setName(String someName)
{
name = someName;
}
//all of the accessor methods - get
public int getAcctNumber()
{
return acctNumber;
}
public double getBalance()
{
return balance;
}
public String getName()
{
return name;
}
public void deposit(double amount)
{
balance = balance + amount;
}
public void withdraw(double amount) {
balance = balance - amount;
}
public String toString()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();
return (" acctNumber " + acctNumber + " balance : " + fmt.format(balance)
+ " name : " + name );
}
//Class method to display our private static variable
public static int getAcctCount()
{
return ( acctCount );
}
}// end of class definition