-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPremium.java
More file actions
43 lines (36 loc) · 1.31 KB
/
Copy pathPremium.java
File metadata and controls
43 lines (36 loc) · 1.31 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
public class Premium extends Account {
private double initialBalance;
private int creditCount=0;
public Premium(String accountId, String accountName, String password, double balance) {
super(accountId, accountName, password, balance);
initialBalance = balance;
super.credit(initialBalance+=initialBalance*.07);
}
public Premium(String accountId, String accountName, String password) {
super(accountId, accountName, password);
initialBalance = 0.0;
super.credit(initialBalance+=initialBalance*.07);
}
public double credit(double amount) {
if(amount>0){
double principle=(amount+getBalance())*.07;
creditCount++;
return super.credit(principle+getBalance());
}
else{
return getBalance();
}
}
public double debit(double amount) {
if(amount>0 && creditCount>=5 && getBalance()>=amount){
return super.debit(getBalance()-amount);
}
else{
System.out.println("Insufficient balance");
return getBalance();
}
}
public String toString() {
return "Account= \n id" + getAccountId() + " accountName=" + getAccountName() + ", balance=" + getBalance();
}
}