Computer Applications
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.
Java
Java Conditional Stmts
ICSE 2014
80 Likes
Answer
import java.util.Scanner;
public class KboatBankDeposit
{
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");
}
}
}Output
![BlueJ output of 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: (a) Term Deposit (b) 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. BlueJ output of 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: (a) Term Deposit (b) 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.](https://cdn1.knowledgeboat.com/img/abp10/1/2014-p8-1.jpg)
![BlueJ output of 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: (a) Term Deposit (b) 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. BlueJ output of 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: (a) Term Deposit (b) 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.](https://cdn1.knowledgeboat.com/img/abp10/1/2014-p8-2.jpg)
![BlueJ output of 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: (a) Term Deposit (b) 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. BlueJ output of 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: (a) Term Deposit (b) 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.](https://cdn1.knowledgeboat.com/img/abp10/1/2014-p8-3.jpg)
Answered By
23 Likes
Related Questions
Write a program to input three numbers (positive or negative). If they are unequal then display the greatest number otherwise, display they are equal. The program also displays whether the numbers entered by the user are 'All positive', 'All negative' or 'Mixed numbers'.
Sample Input: 56, -15, 12
Sample Output:
The greatest number is 56
Entered numbers are mixed numbers.Which of the following is not true with regards to a switch statement?
- checks for an equality between the input and the case labels
- supports floating point constants
- break is used to exit from the switch block
- case labels are unique
A student executes the following program segment and gets an error. Identify the statement which has an error, correct the same to get the output as WIN.
boolean x = true; switch(x) { case 1: System.out.println("WIN"); break; case 2: System.out.println("LOOSE"); }Differentiate between if else if and switch-case statements