# Java menu driven program to calculate the maturity amount of a Bank Deposit using the switch statement

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), rate 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 Instalment (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`

``````import java.util.*;
{
public static void main(string arr[])
{
Scanner sc=new Scanner(System.in);
int ch;
double p,r,n,A;
System.out.println(“M E N U”);
System.out.println(“1. Term deposit”);
System.out.println(“2. Recurring Deposit”);
ch=sc.nextInt();
switch(ch)
{
case 1:
System.out.println(“Enter the principal:”);
p=sc.nextDouble();
System.out.println(“Enter the rate:”);
r=sc.nextDouble();
System.out.println(“Enter the time period:”);
n=sc.nextDouble();
A=p*Math.pow(1+r/100,n);
System.out.println(“Amount=”+A);
break;
case 2:
System.out.println(“Enter the principal:”);
p=sc.nextDouble();
System.out.println(“Enter the rate:”);
r=sc.nextDouble();
System.out.println(“Enter the time period:”);
n=sc.nextDouble();
A=p*n+p*n*(n+1)/2*r/100*1/12.0;
System.out.println(“Amount=”+A);
break;
default:
System.out.println(“Invalid choice!”);
}
}
}``````
`Output`