Untitled
unknown
plain_text
4 months ago
3.3 kB
3
Indexable
import java.util.Scanner; public class FinancialPlanningCalculator { // Method to calculate future value of an investment public static double calculateFutureValue(double principal, double rate, int years) { return principal * Math.pow(1 + rate / 100, years); } // Method to calculate monthly savings required to achieve a goal public static double calculateMonthlySavings(double goalAmount, double rate, int years) { double monthlyRate = rate / (12 * 100); int months = years * 12; return goalAmount * monthlyRate / (Math.pow(1 + monthlyRate, months) - 1); } // Method to calculate loan EMI (Equated Monthly Installment) public static double calculateEMI(double loanAmount, double rate, int years) { double monthlyRate = rate / (12 * 100); int months = years * 12; return (loanAmount * monthlyRate * Math.pow(1 + monthlyRate, months)) / (Math.pow(1 + monthlyRate, months) - 1); } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Welcome to the Financial Planning Calculator!"); System.out.println("Choose an option:"); System.out.println("1. Calculate Future Value of Investment"); System.out.println("2. Calculate Monthly Savings for a Goal"); System.out.println("3. Calculate Loan EMI"); System.out.print("Enter your choice: "); int choice = scanner.nextInt(); switch (choice) { case 1: System.out.print("Enter initial investment amount: "); double principal = scanner.nextDouble(); System.out.print("Enter annual interest rate (in %): "); double rate = scanner.nextDouble(); System.out.print("Enter number of years: "); int years = scanner.nextInt(); double futureValue = calculateFutureValue(principal, rate, years); System.out.printf("Future value of the investment: %.2f\n", futureValue); break; case 2: System.out.print("Enter your goal amount: "); double goalAmount = scanner.nextDouble(); System.out.print("Enter annual interest rate (in %): "); rate = scanner.nextDouble(); System.out.print("Enter number of years: "); years = scanner.nextInt(); double monthlySavings = calculateMonthlySavings(goalAmount, rate, years); System.out.printf("Monthly savings required: %.2f\n", monthlySavings); break; case 3: System.out.print("Enter loan amount: "); double loanAmount = scanner.nextDouble(); System.out.print("Enter annual interest rate (in %): "); rate = scanner.nextDouble(); System.out.print("Enter loan tenure (in years): "); years = scanner.nextInt(); double emi = calculateEMI(loanAmount, rate, years); System.out.printf("Monthly EMI: %.2f\n", emi); break; default: System.out.println("Invalid choice. Please restart the program."); } scanner.close(); } }
Editor is loading...
Leave a Comment