-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBankAccount.java
106 lines (94 loc) · 2.57 KB
/
BankAccount.java
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
package lab9;
/**Defines any type of bank account*/
public abstract class BankAccount
{
/**class variable so that each account has a unique number*/
protected static int numberOfAccounts = 100001;
/**current balance in the account*/
private double balance;
/** name on the account*/
private String owner;
/** number bank uses to identify account*/
private String accountNumber;
/**default constructor*/
public BankAccount()
{
balance = 0;
accountNumber = numberOfAccounts + "";
numberOfAccounts++;
}
/**standard constructor
@param name the owner of the account
@param amount the beginning balance*/
public BankAccount(String name, double amount)
{
owner = name;
balance = amount;
accountNumber = numberOfAccounts + "";
numberOfAccounts++;
}
/**copy constructor creates another account for the same owner
@param oldAccount the account with information to copy
@param the beginning balance of the new account*/
public BankAccount(BankAccount oldAccount, double amount)
{
owner = oldAccount.owner;
balance = amount;
accountNumber = oldAccount.accountNumber;
}
/**allows you to add money to the account
@param amount the amount to deposit in the account*/
public void deposit(double amount)
{
balance = balance + amount;
}
/**allows you to remove money from the account if
enough money is available,returns true if the transaction was
completed, returns false if the there was not enough money.
@param amount the amount to withdraw from the account
@return true if there was sufficient funds to complete
the transaction, false otherwise*/
public boolean withdraw(double amount)
{
boolean completed = true;
if (amount <= balance)
{
balance = balance - amount;
}
else
{
completed = false;
}
return completed;
}
/**accessor method to balance
@return the balance of the account*/
public double getBalance()
{
return balance;
}
/**accessor method to owner
@return the owner of the account*/
public String getOwner()
{
return owner;
}
/**accessor method to account number
@return the account number*/
public String getAccountNumber()
{
return accountNumber;
}
/**mutator method to change the balance
@param newBalance the new balance for the account*/
public void setBalance(double newBalance)
{
balance = newBalance;
}
/**mutator method to change the account number
@param newAccountNumber the new account number*/
public void setAccountNumber(String newAccountNumber)
{
accountNumber = newAccountNumber;
}
}