Problem Statement - Term Deposit Recurring Deposit Calculation
Using the switch statement. write a menu driven program to calculate the maturity amount of a Bank Deposit.
The user is given the following options:
(i) Term Deposit
(ii) Recurring Deposit
For option (i) accept principal(P), rare of ¡interest(r) and time period in years(n). Calculate and output the maturity amount(A) receivable
using the formula
For option (ii) accept Monthly Installment (P), rate of interest(r) and time period in months (n). Calculate and output the maturity amount(A) receivable using the formula
For an incorrect option, an appropriate error message should be displayed.
Solution
TC++ #7439
import java.util.Scanner;
public class Interest {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Menu");
System.out.println("1. Term Deposit");
System.out.println("2. Recurring Deposit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.print("Enter principal: ");
int P1 = scanner.nextInt();
System.out.print("Enter rate of interest: ");
int r1 = scanner.nextInt();
System.out.print("Enter period in years: ");
int n1 = scanner.nextInt();
double maturityAmount1 = P1 * Math.pow(1 + r1 / 100.0, n1);
System.out.println("Maturity Amount is " + maturityAmount1);
break;
case 2:
System.out.print("Enter monthly installment: ");
int P2 = scanner.nextInt();
System.out.print("Enter rate of interest: ");
int r2 = scanner.nextInt();
System.out.print("Enter period in months: ");
int n2 = scanner.nextInt();
double maturityAmount2 = P2 * n2 + P2 * (n2 * (n2 + 1) / 2.0) * (r2 / 100.0) * (1.0 / 12);
System.out.println("Maturity Amount is " + maturityAmount2);
break;
default:
System.out.println("Invalid choice");
}
}
}