Programming Examples

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.*;
class Menu
{
	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”);
		System.out.println(“Enter your choice:”);
		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

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad