Home Java Programming Language / 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: Term Deposit Recurring Deposit For option 1, 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 2, 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 x n + P x (n(n+1) / 2) x r / 100 x 1 / 12 For an incorrect option, an appropriate error message should be displayed.
🚀 Programming Example

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:

  1. Term Deposit
  2. Recurring Deposit

For option 1, 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 2, 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 x n + P x (n(n+1) / 2) x r / 100 x 1 / 12

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

👁 224 Views
💻 Practical Program
📘 Step Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.
No previous program
No next program

📌 Information & Algorithm

]

💻 Program Code

import java.util.Scanner;

public class RAnsariBankDeposit
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("Type 1 for Term Deposit");
        System.out.println("Type 2 for Recurring Deposit");
        System.out.print("Enter your choice: ");
        int ch = in.nextInt();
        double p = 0.0, r = 0.0, a = 0.0;
        int n = 0;

        switch (ch) {
            case 1:
            System.out.print("Enter Principal: ");
            p = in.nextDouble();
            System.out.print("Enter Interest Rate: ");
            r = in.nextDouble();
            System.out.print("Enter time in years: ");
            n = in.nextInt();
            a = p * Math.pow(1 + r / 100, n);
            System.out.println("Maturity amount = " + a);
            break;

            case 2:
            System.out.print("Enter Monthly Installment: ");
            p = in.nextDouble();
            System.out.print("Enter Interest Rate: ");
            r = in.nextDouble();
            System.out.print("Enter time in months: ");
            n = in.nextInt();
            a = p * n + p * ((n * (n + 1)) / 2) * (r / 100) * (1 / 12.0);
            System.out.println("Maturity amount = " + a);
            break;

            default:
            System.out.println("Invalid choice");
        }
    }
}
                        

🖥 Program Output

Type 1 for Term Deposit
Type 2 for Recurring Deposit
Enter your choice: 1
Enter Principal: 10000
Enter Interest Rate: 4
Enter time in years: 3
Maturity amount = 11248.640000000001
Press any key to continue . . .


                            
No previous program
No next program
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.