Computer Applications
Using a switch case statement, write a menu driven program to convert a given temperature from Fahrenheit to Celsius and vice-versa. For an incorrect choice, an appropriate message should be displayed.
Hint: c = 5/9(f-32) and f=1.8c+32
Answer
import java.util.Scanner;
public class KboatTemperature
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Type 1 to convert from Fahrenheit to Celsius");
System.out.println("Type 2 to convert from Celsius to Fahrenheit");
int choice = in.nextInt();
double ft = 0.0, ct = 0.0;
switch (choice) {
case 1:
System.out.print("Enter temperature in Fahrenheit: ");
ft = in.nextDouble();
ct = 5 / 9.0 * (ft - 32);
System.out.println("Temperature in Celsius: " + ct);
break;
case 2:
System.out.print("Enter temperature in Celsius: ");
ct = in.nextDouble();
ft = 1.8 * ct + 32;
System.out.println("Temperature in Fahrenheit: " + ft);
break;
default:
System.out.println("Incorrect Choice");
break;
}
}
}
Variable Description Table
Program Explanation
Output
Related Questions
A company announces revised Dearness Allowance (DA) and Special Allowances (SA) for their employees as per the tariff given below:
Basic Dearness Allowance (DA) Special Allowance (SA) Up to ₹ 10,000 10% 5% ₹ 10,001 - ₹ 20,000 12% 8% ₹ 20,001 - ₹ 30,000 15% 10% ₹ 30,001 and above 20% 12% Write a program to accept name and Basic Salary (BS) of an employee. Calculate and display gross salary.
Gross Salary = Basic + Dearness Allowance + Special Allowance
Print the information in the given format:
Name Basic DA Spl. Allowance Gross Salary
xxx xxx xxx xxx xxxThe volume of solids, viz. cuboid, cylinder and cone can be calculated by the formula:
- Volume of a cuboid (v = l*b*h)
- Volume of a cylinder (v = π*r2*h)
- Volume of a cone (v = (1/3)*π*r2*h)
Using a switch case statement, write a program to find the volume of different solids by taking suitable variables and data types.
Mr. Kumar is an LIC agent. He offers discount to his policy holders on the annual premium. However, he also gets commission on the sum assured as per the given tariff.
Sum Assured Discount Commission Up to ₹ 1,00,000 5% 2% ₹ 1,00,001 and up to ₹ 2,00,000 8% 3% ₹ 2,00,001 and up to ₹ 5,00,000 10% 5% More than ₹ 5,00,000 15% 7.5% Write a program to input name of the policy holder, the sum assured and first annual premium. Calculate the discount of the policy holder and the commission of the agent. The program displays all the details as:
Name of the policy holder :
Sum assured :
Premium :
Discount on the first premium :
Commission of the agent :A Mega Shop has different floors which display varieties of dresses as mentioned
below:- Ground floor : Kids Wear
- First floor : Ladies Wear
- Second floor : Designer Sarees
- Third Floor : Men's Wear
The user enters floor number and gets the information regarding different items of the Mega shop. After shopping, the customer pays the amount at the billing counter and the shopkeeper prints the bill in the given format:
Name of the Shop: City Mart
Total Amount:
Visit Again!!Write a program to perform the above task as per the user's choice.