61.5k views
0 votes
Write an application that calculates and displays the amount of money a user would have if his/her money could be invested at 5% interest for one year. Create a method that prompts the user for the starting value of the investment and returns it to the calling program. Call a separate method to do the calculation and return the result to be displayed. Save the program as Interest.java

1 Answer

1 vote

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;}

}

}

Step-by-step 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

User Ponf
by
7.6k points