In: Computer Science
In java
Create a program to calculate interest rate and total balance - the program consists of
(a) A class that encapsulates the interest rate and total balance calculation
(b) A test program that uses class from step (A) to perform the following:
//Java program
class Account{
private double Balance;
private double interest_rate;
public Account(double bal,double interest) {
Balance = bal;
interest_rate = interest;
}
public void setBalance(double balance) {
Balance = balance;
}
public double getBalance() {
return Balance;
}
public void setInterestRate(double interest) {
interest_rate = interest;
}
public double getInterestRate() {
return interest_rate;
}
}
public class Main {
public static void main(String args[]) {
Account acc = new
Account(1000,5);
double interest =
acc.getBalance()*acc.getInterestRate()/100;
System.out.println("Interest :
"+interest);
System.out.println("Total Balanace
: "+(interest+acc.getBalance()));
acc.setInterestRate(10);
interest =
acc.getBalance()*acc.getInterestRate()/100;
System.out.println("Interest :
"+interest);
System.out.println("Total Balanace
: "+(interest+acc.getBalance()));
acc.setBalance(2000);
interest =
acc.getBalance()*acc.getInterestRate()/100;
System.out.println("Interest :
"+interest);
System.out.println("Total Balanace
: "+(interest+acc.getBalance()));
}
}
//sample output