-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBankAccount
130 lines (113 loc) · 3.03 KB
/
BankAccount
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package assignment2;
/**
* Model for general bank account object. The purpose is to record money,
* and allow for various financial transactions to be performed over the
* life of a specific bank account.
*
* @author ee322c teaching team
*/
class BankAccount
{
// instance variables (protected to allow inheriting them)
/**
* A unique number that identifies the account
*/
protected int accountNumber;
/**
* The name of the person that this account belongs to
*/
protected Customer ownersName;
/**
* the current value (in dollars) of the money in this account
*/
protected double balance;
//constructors
/**
* Create an account with an initial balance.
* @param initialBalance The initial balance of the account
*/
public BankAccount(double initialBalance)
{
balance = initialBalance;
}
/**
* Create an account with initial parameters.
* @param acct The account number
* @param owner The owner of the account
* @param initBalance The initial balance of the account
*/
public BankAccount(int acct, Customer owner, double initBalance)
{
accountNumber = acct;
ownersName = owner;
balance = initBalance;
}
// balance changing methods
/**
* Updates the current balance by adding in a given amount.
* Post condition: the new balance is increased by the amount.
* @param amount The amount to add
*/
public void deposit(double amount)
{
balance = balance + amount;
}
/**
* Update the current balance by subtracting the given amount.
* Precondition: the current balance must have at least the amount in it.
* Postcondition: the new balance is decreased by the given amount.
* @param amount The amout to subtract
*/
public void withdraw(double amount)
{
if (balance >= amount)
balance = balance - amount;
}
// get and set methods
/**
* @return The available balance.
*/
public double getBalance( )
{
return balance;
}
/**
* @return The account number.
*/
public int getAccountNumber( )
{
return accountNumber;
}
/**
* @return The owner's name.
*/
public Customer getOwner( )
{
return ownersName;
}
// set: postconditions- these all are used to set new values for the instance variables
/**
* Set the balance.
* @param newBalance The new balance.
*/
public void setBalance(double newBalance )
{
balance = newBalance;
}
/**
* Set the acount number.
* @param newAcctNumber The new account number.
*/
public void setAccountNumber(int newAcctNumber )
{
accountNumber = newAcctNumber;
}
/**
* Set the new owner of the account.
* @param newOwner
*/
public void setOwner(Customer newOwner )
{
ownersName = newOwner;
}
}