C Programs Tutorials | IT Developer
IT Developer

Java Programs



Share with a Friend

Menu Driven - Bank Deposit Program - Java Programs

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:

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 * n + p * n(n + 1) / 2 * r / 100 * 1 / 12.

For an incorrect option, an appropriate error message should be displayed.

import java.util.Scanner; class Deposit{ public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.println("1. Term Deposit"); System.out.println("2. Recurring Deposit"); System.out.print("Enter your choice: "); int choice = Integer.parseInt(in.nextLine()); switch(choice){ case 1: System.out.print("Principal: "); double p = Double.parseDouble(in.nextLine()); System.out.print("Rate of interest: "); double r = Double.parseDouble(in.nextLine()); System.out.print("Time period: "); double n = Double.parseDouble(in.nextLine()); double a = p * Math.pow(1 + r / 100, n); System.out.println("Maturity amount: " + a); break; case 2: System.out.print("Monthly installment: "); p = Double.parseDouble(in.nextLine()); System.out.print("Rate of interest: "); r = Double.parseDouble(in.nextLine()); System.out.print("Time period: "); n = Double.parseDouble(in.nextLine()); a = p * n + p * n * (n + 1) / 2 * r / 100 * 1 / 12; System.out.println("Maturity amount: " + a); break; default: System.out.println("Invalid choice!"); } } }

Output

 
 OUTPUT 1: 
1. Term Deposit
2. Recurring Deposit
Enter your choice: 1
Principal: 10000
Rate of interest: 6.5
Time period: 10
Maturity amount: 18771.37465269359 

 OUTPUT 2: 
1. Term Deposit
2. Recurring Deposit
Enter your choice: 2
Monthly installment: 1000
Rate of interest: 6
Time period: 10
Maturity amount: 10275.0