-
Notifications
You must be signed in to change notification settings - Fork 0
/
Driver2_Protected_Super.java
60 lines (47 loc) · 1.15 KB
/
Driver2_Protected_Super.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
package driver_2;
class InterestBearingAccount extends Account{
private static double default_interest = 7.95;
private double interest_rate;
public InterestBearingAccount(double amount, double interest) {
super(amount);
interest_rate = interest;
}
public InterestBearingAccount(double amount) {
balance = amount;
interest_rate = default_interest;
}
public void add_monthly_interest() {
balance = balance + (balance * interest_rate/100)/12;
}
}
class Account{
protected double balance;
public Account(double amount){
balance = amount;
}
public Account() {
balance = 0.0;
}
public void deposit(double amount) {
balance += amount;
}
public double withdraw(double amount) {
if(balance >= amount) {
balance -= amount;
return amount;
}
else
return 0.0;
}
public double getBalance() {
return balance;
}
}
public class Driver2 {
public static void main(String[] args) {
InterestBearingAccount ac1 = new InterestBearingAccount(1000.0 , 5.0);
ac1.add_monthly_interest();
ac1.withdraw(100.0);
System.out.println("balance = " + ac1.getBalance());
}
}