+ 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.
10 Respostas
+ 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);
}
}
+ 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.
+ 1
See if this works.
https://code.sololearn.com/cF7Achso22V8/?ref=app
0
Hi
- 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
- 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)
- 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..!!!
- 1
Attunuru Baby Sri Laya code updated
- 1
Lila
- 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;
}
}