-
Notifications
You must be signed in to change notification settings - Fork 0
/
BankAccount.java
95 lines (75 loc) · 1.74 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
/**
The BankAccount class simulates a bank account.
*/
public class BankAccount
{
private double balance; // Account balance
/**
This constructor sets the starting balance
at 0.0.
*/
public BankAccount()
{
balance = 0.0;
}
/**
This constructor sets the starting balance
to the value passed as an argument.
@param startBalance The starting balance.
*/
public BankAccount(double startBalance)
{
balance = startBalance;
}
/**
This constructor sets the starting balance
to the value in the String argument.
@param str The starting balance, as a String.
*/
public BankAccount(String str)
{
balance = Double.parseDouble(str);
}
/**
The deposit method makes a deposit into
the account.
@param amount The amount to add to the
balance field.
*/
public void deposit(double amount)
{
balance += amount;
}
public void deposit(String str){
// balance += Double.parseDouble(str);
//or
deposit(Double.parseDouble(str));
}
/**
The withdraw method withdraws an amount
from the account.
@param amount The amount to subtract from
the balance field.
*/
public void withdraw(double amount)
{
balance -= amount;
}
/**
The setBalance method sets the account balance.
@param b The value to store in the balance field.
*/
public void setBalance(double balance)
{
this.balance = balance;
}
/**
The getBalance method returns the
account balance.
@return The value in the balance field.
*/
public double getBalance()
{
return balance;
}
}