Update OOP/Java/Lab/Week6/Account/AccountManagement.java
This commit is contained in:
parent
ab8e519672
commit
ec68dc6815
@ -12,6 +12,10 @@ class Account {
|
|||||||
this.accountType = accountType;
|
this.accountType = accountType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected double getBalanceInternal() {
|
||||||
|
return balance;
|
||||||
|
}
|
||||||
|
|
||||||
public void deposit(double amount) {
|
public void deposit(double amount) {
|
||||||
balance += amount;
|
balance += amount;
|
||||||
}
|
}
|
||||||
@ -39,12 +43,12 @@ class SavingsAccount extends Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void computeInterest() {
|
public void computeInterest() {
|
||||||
double interest = balance * interestRate / 100;
|
double interest = getBalanceInternal() * interestRate / 100;
|
||||||
deposit(interest);
|
deposit(interest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void withdraw(double amount) {
|
public void withdraw(double amount) {
|
||||||
if (amount > getBalance()) {
|
if (amount > getBalanceInternal()) {
|
||||||
System.out.println("Insufficient balance");
|
System.out.println("Insufficient balance");
|
||||||
} else {
|
} else {
|
||||||
super.withdraw(amount);
|
super.withdraw(amount);
|
||||||
@ -64,14 +68,14 @@ class CurrentAccount extends Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void checkMinimumBalance() {
|
public void checkMinimumBalance() {
|
||||||
if (getBalance() < minimumBalance) {
|
if (getBalanceInternal() < minimumBalance) {
|
||||||
withdraw(serviceTax);
|
withdraw(serviceTax);
|
||||||
System.out.println("Service tax imposed");
|
System.out.println("Service tax imposed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void withdraw(double amount) {
|
public void withdraw(double amount) {
|
||||||
if (amount > getBalance()) {
|
if (amount > getBalanceInternal()) {
|
||||||
System.out.println("Insufficient balance");
|
System.out.println("Insufficient balance");
|
||||||
} else {
|
} else {
|
||||||
super.withdraw(amount);
|
super.withdraw(amount);
|
||||||
@ -86,15 +90,19 @@ public class AccountManagement {
|
|||||||
SavingsAccount saurabhAccount = new SavingsAccount("Saurabh", 1234, 10000, 5);
|
SavingsAccount saurabhAccount = new SavingsAccount("Saurabh", 1234, 10000, 5);
|
||||||
CurrentAccount akhilAccount = new CurrentAccount("Akhil", 5678, 5000, 1000, 500);
|
CurrentAccount akhilAccount = new CurrentAccount("Akhil", 5678, 5000, 1000, 500);
|
||||||
|
|
||||||
saurabhAccount.deposit(5000);
|
System.out.println("Initial balances:");
|
||||||
System.out.println("Saurabh's balance: " + saurabhAccount.getBalance());
|
System.out.println("Saurabh's balance: " + saurabhAccount.getBalance());
|
||||||
|
System.out.println("Akhil's balance: " + akhilAccount.getBalance());
|
||||||
|
|
||||||
|
saurabhAccount.deposit(5000);
|
||||||
|
System.out.println("Saurabh's balance after deposit: " + saurabhAccount.getBalance());
|
||||||
saurabhAccount.computeInterest();
|
saurabhAccount.computeInterest();
|
||||||
System.out.println("Saurabh's balance after interest: " + saurabhAccount.getBalance());
|
System.out.println("Saurabh's balance after interest: " + saurabhAccount.getBalance());
|
||||||
saurabhAccount.withdraw(2000);
|
saurabhAccount.withdraw(2000);
|
||||||
System.out.println("Saurabh's balance after withdrawal: " + saurabhAccount.getBalance());
|
System.out.println("Saurabh's balance after withdrawal: " + saurabhAccount.getBalance());
|
||||||
|
|
||||||
akhilAccount.deposit(2000);
|
akhilAccount.deposit(2000);
|
||||||
System.out.println("Akhil's balance: " + akhilAccount.getBalance());
|
System.out.println("Akhil's balance after deposit: " + akhilAccount.getBalance());
|
||||||
akhilAccount.withdraw(3000);
|
akhilAccount.withdraw(3000);
|
||||||
System.out.println("Akhil's balance after withdrawal: " + akhilAccount.getBalance());
|
System.out.println("Akhil's balance after withdrawal: " + akhilAccount.getBalance());
|
||||||
akhilAccount.checkMinimumBalance();
|
akhilAccount.checkMinimumBalance();
|
||||||
|
Loading…
Reference in New Issue
Block a user