67.5k views
4 votes
Create the logic for a program that calculates and displays the amount of money you would have if you invested $5000 at 2 percent simple interest for one year. Create a separate method to do the calculation and return the result to be displayed.

User JeanLuc
by
6.0k points

1 Answer

6 votes

Answer:

/* interest = principal amount * rate*time

Total amount = principal + interest

*/

See a java program with a method that implements the solution in the explanation section

Step-by-step explanation:

public class num6 {

public static void main(String[] args) {

double capital = 5000;

int noYears = 1;

double intRate = 0.02;

System.out.println("Interest is "+simpleInterest(capital,noYears,intRate));

double totalAmount = capital + simpleInterest(capital,noYears,intRate);

System.out.println("Total Amount is "+totalAmount);

}

public static double simpleInterest(double capital, int timeInYears, double rateInPercentage){

double interest = capital*timeInYears*rateInPercentage;

return interest;

}

}

User Anthoni Gardner
by
5.7k points