You are writing a program that calculates interest income based on account type. If it is a saving account, 20% is added to the balance in the account. If it is a checking account, 5% more is added to the balance in the account.
The program you are given should the balance of the savings and checking accounts and output the appropriate balance plus interest income
Account class and SavingAcc & CheckingAcc classes inherited from it are already defined.
Override getIncome() methods in the inherited classes to calculate and return the account balances, so that the given outputs work correctly.
Sample Input
100.0
100.0
Sample Output
120.0
105.0
/*
Write a program that calculates the income based on the type of the account.
***************************************************************************
Overriding
You are writing a program that calculates interest income based on account type. If it is a saving account, 20% is added to the balance in the account. If it is a checking account, 5% more is added to the balance in the account.
The program you are given should the balance of the savings and checking accounts and output the appropriate balance plus interest income
Account class and SavingAcc & CheckingAcc classes inherited from it are already defined.
Override getIncome() methods in the inherited classes to calculate and return the account balances, so that the given outputs work correctly.
*/
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
double saving = read.nextDouble();
double checking = read.nextDouble();
Account savingAcc = new SavingAcc(saving);
Account checkingAcc = new CheckingAcc(checking);
System.out.println(savingAcc.getIncome());
System.out.println(checkingAcc.getIncome());
}
}
class Account {
protected double amount;
public Account(double amount) {
this.amount = amount;
}
public double getAmount() {
return amount;
}
public double getIncome() {
return 0;
}
}
class SavingAcc extends Account {
public SavingAcc(double amount) {
super(amount);
}
//Override the method for saving account
public double getIncome() {
amount=amount+amount*0.2;
return amount;
}
}
class CheckingAcc extends Account {
public CheckingAcc(double amount) {
super(amount);
}
//Override the method for checking account
public double getIncome() {
amount=amount+amount*0.05;
return amount;
}
}