-
Notifications
You must be signed in to change notification settings - Fork 0
/
Savings.java
73 lines (63 loc) · 2.05 KB
/
Savings.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
package a2;
/*
* Filename: Savings.java
* Developer: Shatil Rahman
* Developer student id (lol): 260606042
* Last modified: 9:00PM 1/19/2018
* Purpose: - Class for savings account.
* - Contains methods specific to savings accounts, as opposed to savings accounts
*/
public class Savings extends Account {
public Savings(int customerNo, int accountNo, float balance) {
super(customerNo, accountNo, balance);
}
public boolean deposit(float amount, float discountPercent) {
/*
* Makes a deposit into the savings account
* Input: amount - amount to be added, must be positive value or 0
* discountPercent - deposit bonus is increase by this percent
* - must be a positive float between 0 and 1
* Returns: true if successful, false if failed
*/
float currentBalance = this.getBalance();
float bonus = (float)1.0 * discountPercent;
if(amount <=0) {
System.out.println("Amount to be deposited must be a positive number");
return false;
}
else {
if(this.setBalance(currentBalance + amount + bonus) == false) {
return false;
}
else {
System.out.println("Bonus for deposit earned! Value: " + bonus );
System.out.println("Deposit successful, current balance is: " + this.getBalance());
return true;
}
}
}
public boolean withdraw(float amount) {
/*
* Makes a withdrawal from the checking account
* Input: amount - amount to be withdrawn, must be positive number
* Returns: true if successful, false if failed
*/
float currentBalance = this.getBalance();
if(amount <=0) {
System.out.println("Amount to be withdrawn must be a positive number");
return false;
}
else if(amount < 1000.0) {
System.out.println("Must withdraw greater than or equal to $1000!");
return false;
}
else {
if(this.setBalance(currentBalance - amount) == false) {
return false;
}else {
System.out.println("Withdrawal successful, current balance is: " + this.getBalance());
return true;
}
}
}
}