+ 1

How to calculate interest income based on account type?

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.

3rd Jan 2021, 3:17 PM
Sri Laya
Sri Laya - avatar
10 ответов
+ 3
import java.util.Scanner; //Please Subscribe to My Youtube Channel //Channel Name: Fazal Tuts4U 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 { private 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() { return getAmount() + (getAmount()*0.2); } } class CheckingAcc extends Account { public CheckingAcc(double amount) { super(amount); } //Override the method for checking account public double getIncome() { return getAmount() + (getAmount()*0.05); } }
4th Sep 2021, 9:57 AM
Fazal Haroon
Fazal Haroon - avatar
+ 1
For savings account- amount + (amount * 0.2) For checking account- amount + (amount * 0.05) Edit: This will give total amount. You can do just (amount * 0.2) or (amount * 0.05) to get the interest amount alone. Also this is for one year.
3rd Jan 2021, 3:31 PM
Avinesh
Avinesh - avatar
3rd Jan 2021, 3:55 PM
Avinesh
Avinesh - avatar
0
Hi
4th Jan 2021, 1:13 PM
Mohammad Amial
Mohammad Amial - avatar
- 1
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 { private 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() { } } class CheckingAcc extends Account { public CheckingAcc(double amount) { super(amount); } //Override the method for check
3rd Jan 2021, 3:22 PM
Sri Laya
Sri Laya - avatar
- 1
The above one is the code....Could anyone please explain me to how to do that using the required formula...!!!! (I think the formula might be Simple interest i = p*t*r)
3rd Jan 2021, 3:24 PM
Sri Laya
Sri Laya - avatar
- 1
But i have to get the balance + interest income From ur code i couldn't get the required answer which is asked in question...!! In this code the output for 100,100 is 20,25...!! But i have to get 120,125..!!!
3rd Jan 2021, 4:08 PM
Sri Laya
Sri Laya - avatar
- 1
3rd Jan 2021, 4:25 PM
Avinesh
Avinesh - avatar
- 1
Lila
4th Jan 2021, 1:13 PM
Mohammad Amial
Mohammad Amial - avatar
- 1
try this code 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 { private 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() { // return the income with 10 percent extra on saving return this.getAmount()+this.getAmount()*0.20; } } class CheckingAcc extends Account { public CheckingAcc(double amount) { super(amount); } //Override the method for checking account public double getIncome() { // return the income with 5 percent extra on checking return this.getAmount() + this.getAmount()*0.05; } }
30th May 2021, 4:06 AM
Abhishek Biswas
Abhishek Biswas - avatar