From 0f8de1a0b91420ca6261a9470abb9f30d5ef22c8 Mon Sep 17 00:00:00 2001 From: Cameron Seamons Date: Mon, 5 Jan 2026 21:12:29 -0700 Subject: [PATCH] created compound calculator --- practice_projects/src/compountInterest.java | 43 +++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 practice_projects/src/compountInterest.java diff --git a/practice_projects/src/compountInterest.java b/practice_projects/src/compountInterest.java new file mode 100644 index 0000000..5f6bb3d --- /dev/null +++ b/practice_projects/src/compountInterest.java @@ -0,0 +1,43 @@ +import java.util.Scanner; + +public class compountInterest { + + public static void main(String[] args) { + + // Compound interest calculator + + Scanner scanner = new Scanner(System.in); + + // Initialize variables + double principal; + double rate; + int timesCompounded; + int years; + double amount; + + // get inputs + System.out.print("Enter the principal amount: "); + principal = Double.valueOf(scanner.nextLine()); + + System.out.print("Enter the interest rate (in %): "); + rate = Double.valueOf(scanner.nextLine()) / 100; + + System.out.print("Enter the # of times compounded per year: "); + timesCompounded = Integer.valueOf(scanner.nextLine()); + + System.out.print("Enter the # of years: "); + years = Integer.valueOf(scanner.nextLine()); + + // Calculate the compound interest + amount = principal * Math.pow(1 + rate / timesCompounded, timesCompounded * years); + + // Print out the results + System.out.printf("\nThe amount after %d years is: $ %.2f", years, amount); + + + + scanner.close(); + + + } +}