Answer:
// Application in java.
// package
import java.util.*;
// class definition
class Main
{
// method for calculating interest
public static float calculateInterest(float start_bal,float i_Rate)
{
// calculate return
float return_Amount=start_bal+(start_bal*(i_Rate/100));
// return
return return_Amount;
}
// main method of the class
public static void main (String[] args) throws java.lang.Exception
{
try{
// scanner Object to read the input
Scanner sc = new Scanner(System.in);
// variables
float start_bal;
float i_Rate=5;
// ask to enter start money
System.out.print("Enter start money:");
// read start money
start_bal=sc.nextFloat();
// call the function and print the return amount
System.out.println("5% interest earned on $" + start_bal + " after one year is $" + calculateInterest(start_bal,i_Rate));
}catch(Exception ex){
return;}
}
}
Explanation:
Declare and initialize interest rate with 5.Then read the start money from user.Then call the method calculateInterest() with parameter start_bal and i_Rate.It will calculate the return amount after 1 year.Print the returned amount in main method.
Output:
Enter start money:1500
5% interest earned on $1500.0 after one year is $1575.0