icse-promo

Question

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:

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

P*n+(P*(n*(n+1))/2)*(r/100)*(1/12)

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

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;

public class program8
{
    public static void main(String[] args)
    {
        int choice=0;
        double maturityAmount=0;
        Scanner sc = new Scanner(System.in);
        System.out.println("Press 1 for Term Deposit");
        System.out.println("Press 2 for Recurring Deposit");
        System.out.print("Enter your choice: ");
        choice = sc.nextInt();
        switch (choice)
        {
            case 1:
            System.out.print("Enter principal: ");
            double P1 = sc.nextDouble();
            System.out.print("Enter rate of interest: ");
            double r1 = sc.nextDouble();
            System.out.print("Enter period in years: ");
            double n1 = sc.nextDouble();
            /* maturity amount = p*((1+r1)/100)^n1 */
            maturityAmount = P1 * Math.pow(1 + r1 / 100.0, n1);
            System.out.println("Maturity Amount is " + maturityAmount);
            break;
            case 2:
            System.out.print("Enter monthly installment: ");
            double P2 = sc.nextDouble();
            System.out.print("Enter rate of interest: ");
            double r2 = sc.nextDouble();
            System.out.print("Enter period in months: ");
            double n2 = sc.nextDouble();
            /* Maturity amount=p2 *n2 +p2*(n2*(n2+1)/2)*(r2/100)*(1/12) */
            maturityAmount = P2 * n2 + P2 * (n2 * (n2 + 1) / 2.0) * (r2 / 100.0) * (1.0 / 12);
            System.out.println("Maturity Amount is " + maturityAmount);
            break;
            default:
            System.out.println("Invalid choice");
        }
    }
}

				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *