-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterest.java
42 lines (29 loc) · 1.11 KB
/
Interest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* @author arieldanon
* @version 13 Feb 2024
*/
// import Scanner
import java.util.Scanner;
public class Interest {
public static void main(String[] args){
// Create instance of the new scanner class
Scanner input = new Scanner(System.in);
//prompt the user for the principal amount
System.out.print("How much to invest? $");
// declare principal and assign
double principal = input.nextDouble();
// prompt user for interest rate
System.out.print("What is the rate of return (As a decimal)? ");
//declare the rate
double rate = input.nextDouble();
// prompt user for the number of years
System.out.print("How many years will you hold this investment? ");
//declare and assign the years
int years = input.nextInt();
// increment from 1 to the number of years
for (int counter = 1; counter <= years; counter++) {
System.out.printf("The amount after %d year(s) is: $%15.2f%n", counter, principal * Math.pow(1+rate, counter));
}
System.out.println();
}
}