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
Advertisements
प्रश्न
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 m years(n). Calculate and output the maturity amount (A) receivable using the formula
`"A" = "P"[1+"r"/100]^"n"`
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
`"A" = "P" xx "n" + "P" xx ("n"("n" + 1))/2 xx "r"/100 xx 1/12`
For an incorrect option, an appropriate error message should be displayed.
Advertisements
उत्तर
import java io*:
class Bank
{
public static void main ( ) throws IOException
{
InputStreamReader IR = new InputStreamReader (System.in);
BufferedReader br = new BuffereReader (IR);
System.out.println ("User Menu");
System.out.println ("1. Term Deposite");
System.out.println ("2. Recurring deposits");
System.out.println ("Enter the choice (1 or 2) :");
int ch = Integer.parseInt (br.readLine ( ));
switch (ch)
{
case 1: System.out.println("Enter principal :");
float P = Float.parseFloat (br.readLine ( ));
System.out.println ("Enter rate of interest :");
float r = Float.parseFloat (br.readLine ( ));
System.out.println ("Enter time period in years :");
float n = Float.parse Float (br.readLine ( ));
double a = 1 + (r/100);
double A = P * pow (a,n);
System.out.println ("Maturity Amount" : + "A");
break
case 2 : System.out.println ("Enter Monthly installment")
P = Float.parseFloat (br.readLine ());
System.out.println ("Enter Rate of Interest :");
r = Float.parseFloat (br.readLine ( ));
System.out.println ("Enter time period in months :");
n = Float.parseFloat br.raedLine ( ));
double a = (r/100)*(1/12);
double b = (n*(n+1)/2)*a;
double A = (P * n)+ (P * b);
System.out.println ("Maturity Amount :" + "A");
break;
default : System.out.println ("Wrong choice");
}
}
}
