Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program that allows users to convert temperatures from Celsius to Fahrenheit and Kelvin. The program also evaluates whether the converted Fahrenheit temperature

Write a Java program that allows users to convert temperatures from Celsius to
Fahrenheit and Kelvin. The program also evaluates whether the converted
Fahrenheit temperature indicates a normal body temperature, a fever, or if it's
slightly elevated. Your task is to analyze the provided code, run it, and then
enhance it based on the requirements below.
The user will be given an option to select option 1 or 2 or 3
- If the user selects option 1 then the user will need to enter the Temperature in
Celsius
Convert it to Fahrenheit
Fahrenheit=(9.0/5)* Celsius +32
Then Evaluate the temperature:
-98\deg F to 99\deg F is considered normal.
- Above 100.4\deg F is considered a fever.
- Other values are considered slightly elevated.
- If the user selects option 2 then the user will need to enter the Temperature in
Celsius
Conver to Kelvin
Kelvin = Celsius +273.15
- If the user select option 3
Displays a message thanking the user for their time (as shown on the Sample
Run)
Invalid option. If the user selects any other number, display an error message
(as shown on the Sample Run)
write the java code from this
import java.util.Scanner; // Needed for the Scanner class
/**
* This program demonstrates the if statement
*/
class IfDemo
{
public static void main(String[] args)
{
char choice; // To store the user's choice
int option;
int number;
// Create a Scanner object to read input.
Scanner keyboard = new Scanner(System.in);
//user enter name then separate first name and last name
System.out.println("Enter your name ");
String inputfName=keyboard.next();
System.out.println("your first name is "+inputfName);
String inputLName=keyboard.next();
System.out.println("your last name is "+inputLName);
System.out.print("Enter your options 1,2 or 3:
");
System.out.println("1: For charactors");
System.out.println("2: Even or divisible by 5");
System.out.println("3: Exit");
option=keyboard.nextInt();
if(option==1){
// Ask the user to enter A, B, or C.
System.out.print("Enter A, B, or C: ");
// Read the first character of the string
choice = keyboard.next().charAt(0);
// choice = input.charAt(0); // Get the first char
// Determine which character the user entered.
if(choice=='A'){
System.out.println("You entered A.");
}else if(choice=='B'){
System.out.println("You entered B.");
}else if(choice=='C'){
System.out.println("You entered C.");
}else{
System.out.println("That's not A, B, or C!");
}
}//option=1
else if(option==2){
System.out.print("Enter a number: ");
number = keyboard.nextInt();
if(number%2==0){
System.out.println("number is even");}
else{
System.out.println("number is not even");
}
if(number%5==0){
System.out.println("number is divisible by 5");
}else{
System.out.println("number is not divisable by 5");
}
}//option=2
else if(option==3){
System.out.println("You didn't enter 1 or 2");
System.out.println("Good bye");
}else{
System.out.println("Thank you for your time!");
}
}//main
}//SwitchDemo

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo, Susan D. Urban, Karen C. Davis

4th Edition

1284231585, 978-1284231588

More Books

Students also viewed these Databases questions

Question

3.4 Define HRIS and describe its main components.

Answered: 1 week ago