Create a free account on Computer Sir Ki Class and unlock access to valuable learning resources.
Exam Paper Downloads: After registering and logging in, you can download exam question papers in PDF format to practice and prepare for your exams.
Student Support: Get assistance with your doubts, queries, and questions related to your studies. Our support is here to help you understand topics and resolve your learning difficulties.
Register today and make your exam preparation easier and more effective!
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), rare 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 Installment (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.
Answer:
import java.util.Scanner;
public class Interest {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Menu");
System.out.println("1. Term Deposit");
System.out.println("2. Recurring Deposit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.print("Enter principal: ");
int P1 = scanner.nextInt();
System.out.print("Enter rate of interest: ");
int r1 = scanner.nextInt();
System.out.print("Enter period in years: ");
int n1 = scanner.nextInt();
double maturityAmount1 = P1 * Math.pow(1 + r1 / 100.0, n1);
System.out.println("Maturity Amount is " + maturityAmount1);
break;
case 2:
System.out.print("Enter monthly installment: ");
int P2 = scanner.nextInt();
System.out.print("Enter rate of interest: ");
int r2 = scanner.nextInt();
System.out.print("Enter period in months: ");
int n2 = scanner.nextInt();
double maturityAmount2 = P2 * n2 + P2 * (n2 * (n2 + 1) / 2.0) * (r2 / 100.0) * (1.0 / 12);
System.out.println("Maturity Amount is " + maturityAmount2);
break;
default:
System.out.println("Invalid choice");
}
}
}
C. Sir| Created: 18-Apr-2019 | Updated: 18-Apr-2019|ICSE2014