-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSavingsAccount.java
More file actions
125 lines (112 loc) · 2.29 KB
/
SavingsAccount.java
File metadata and controls
125 lines (112 loc) · 2.29 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import java.util.ArrayList;
/**
* SavingsAccount
* @author MasonSilber
* This method models a savings account
*/
public class SavingsAccount {
private String name;
private double balance;
public static double interestRate = 0.014;//arbitrary
private ArrayList<Double> transactions;
/**
* Constructor
* @param customer The name of the customer
* @param initialBalance Initial balance in the account
*/
public SavingsAccount(String customer, double initialBalance)
{
name = customer;
balance = initialBalance;//Starting amount
transactions = new ArrayList<Double>();
}
/**
* Set Interest Rate
* @param rate The rate to which you set the account's interest rate
*/
public void setInterestRate(double rate)
{
interestRate = rate;
}
/**
* Set Balance
* @param newBalance The balance to which you set the account's balance
*/
public void setBalance(double newBalance)
{
balance = newBalance;
}
/**
* Get Interest Rate
* @return Interest Rate
*/
public double getInterestRate()
{
return interestRate;
}
/**
* Get Name
* @return Name of customer
*/
public String getName()
{
return name;
}
/**
* Get Balance
* @return Account's balance
*/
public double getBalance()
{
return balance;
}
/**
* Get Transactions
* @return List of Transactions
*/
public ArrayList<Double> getTransactions()
{
return transactions;
}
/**
* Deposit
* @param deposit the amount being deposited
*/
public void deposit(double deposit)
{
balance += deposit;
transactions.add(deposit);
}
/**
* Withdraw
* @param withdrawl the amount being withdrawn
*/
public void withdraw(double withdrawl)
{
double overdraftFee = 20;
balance -= withdrawl;
transactions.add(-1*withdrawl);
if(balance < 0)
{
System.err.println("You've overdrafted your account. A $20 fee will be assessed.");
balance -= overdraftFee;
}
}
/**
* Compute interest
* When interest is computed is arbitrary (most often continuous compounding),
* so I just have a computeInterest method which adds the interest to the money in the account
*/
public void computeInterest()
{
balance *= (1+interestRate);
}
/**
* Reset balance
* This is for convenience when using JUnit test cases
*/
public void resetBalance()
{
balance = 1000;
}
}