Question

B - Temperatures You may use the CodeCheck IDE directly to write this program. (Your program...

B - Temperatures

You may use the CodeCheck IDE directly to write this program. (Your program will be graded by CodeCheck). Here are the requirements:

  • Complete the class Temperatures (you must use this exact name to pass CodeCheck) so that it prompts the user for a temperature value, followed by a character that represents the type of temperature.

  • The second input value is the string "F" for Fahrenheit or "C" for Celsius.

  • If the string is an "F", the temperature read was Fahrenheit, which needs to be converted to Celsius.      

  • If the string is a "C", the temperature read was Celsius, which needs to be converted to Fahrenheit.

  • If the character represents Fahrenheit temperature (F), convert the temperature value to the equivalent value in Celsius, using the following formula:

C = (5/9)(F - 32.0)

  • where C represents the Celsius temperature value, and F represents the Fahrenheit temperature value.

  • If the character represents Celsius temperature (C), convert the temperature value to the equivalent value in Fahrenheit, using the following formula:

F = (9/5)C + 32.0

  • The converted temperature is then printed.

http://codecheck.it/files?repo=jfe1cc&problem=ch03/c03_exp_3_102

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

import java.util.Scanner;
/**
* A program that reads in a temperature in degrees that may
* be
farhenheit or may be celsius. The second input value
* is the string "F" or "C . If "F" convert to "C".
* If "C" convert it to "F".
*/

public class Temperatures {

public static void main(String[] args) {
// Define constants
double convertedTemp;
//program
  
//Displaying prompt for temperature
System.out.println("Please enter the temperature in degrees: ");
  
//Read temperature
Scanner in = new Scanner(System.in);
double temp = in.nextDouble();
  
//Displaying prompt for character
System.out.println("Enter F for Farhenheit or C for Celsius: ");
  
//Read char
String type = in.next();
char ttype=type.charAt(0);
  
//Computing and printing farheinheit or celcius
//Checking if type is celsius
if(ttype == 'c' || ttype == 'C') {
//Converting the celsius to farhenheit using given formula
convertedTemp = temp * 9/5 + 32;
//printing out the answer
System.out.print("Converted temp from celsius to farhenheit is ");
System.out.print(convertedTemp);
}
//Checking if given type is farhenheit
else if(ttype == 'f' || ttype == 'F') {
//Converting the farhenheit to celsius using given formula
convertedTemp = ((temp - 32)*5)/9;
//printing out the answer
System.out.print("Converted temp from farhenheit to celsius is ");
System.out.print(convertedTemp);
}
//If users enters the wrong character or type then ask to specify correctly
else {
System.out.println("Please specify character correctly");
}


}

}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
B - Temperatures You may use the CodeCheck IDE directly to write this program. (Your program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Python, write a program that converts Celsius temperatures to Fahrenheit temperatures. The formula is as...

    In Python, write a program that converts Celsius temperatures to Fahrenheit temperatures. The formula is as follows: F=(9/5)C+32 The program should ask the user to enter a temperature in Celsius, then display the temperature converted to Fahrenheit.

  • Write a program that converts Celsius temperatures to Fahrenheit temperatures. The formula is as follows: F=95C+32...

    Write a program that converts Celsius temperatures to Fahrenheit temperatures. The formula is as follows: F=95C+32 The program should ask the user to enter a temperature in Celsius, and then display the temperature converted to Fahrenheit. I'm doing this on Python.

  • Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin...

    Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin Newton Your program should take a character which represents the temperature to convert from and a value to be converted to using the following specification: C - Celsius K - Kelvin N - Newton In addition your program should take in the following character to exit the program: X - eXit the program The numeric input for your program should be of type double....

  • Write a C++ console application that displays a table of Celsius temperatures from 0 through 20...

    Write a C++ console application that displays a table of Celsius temperatures from 0 through 20 and their equivalent Fahrenheit temperature values. The formula for converting from Celsius to Fahrenheit is: [In C++ Please] F==C + 32 Where, C is the temperature value in Celsius, and F is the equivalent temperature in Fahrenheit. Your program must use a loop to display the temperature values.

  • Write a program that displays a table of Celsius temperatures 0 through a number entered by...

    Write a program that displays a table of Celsius temperatures 0 through a number entered by the user and their Fahrenheit equivalents as in the figure below. The formula for converting a Celsius temperature to a Fahrenheit temperature is: F = 9 / 5 * C + 32 where F is the Fahrenheit temperature and C is the Celsius Temperature. Your program must use a 'for' loop. Display all temperatures to one decimal place. Write a program that displays a...

  • Using the latest version of Java JDK, Create a version of this TempConverter program to convert...

    Using the latest version of Java JDK, Create a version of this TempConverter program to convert from Fahrenheit to Kelvin. Read the Fahrenheit temperature from the user. public class TempConverter { //----------------------------------------------------------------- // Computes the Fahrenheit equivalent of a specific Celsius // value using the formula F = (9/5)C + 32. //----------------------------------------------------------------- public static void main (String[] args) { final intBASE = 32; final double CONVERSION_FACTOR = 9.0 / 5.0; double fahrenheitTemp; intcelsiusTemp= 24; // value to convert fahrenheitTemp= celsiusTemp*...

  • 8.) Write a C++ program to convert temperature in degrees Fahrenheit to degrees Celsius. This is...

    8.) Write a C++ program to convert temperature in degrees Fahrenheit to degrees Celsius. This is the equation for this conversion: Celsius = 5.0/9.0 (Fahrenheit-32.0) Have your program convert and display the Celsius temperature corresponding to 98.6 degrees Fahrenheit. Your program should produce the following display (replacing the underlines with the correct values): For a Fahrenheit temperature of-_ degrees, the equivalent Celsius temperature is degrees

  • python Write a program that displays a table of Celsius temperatures and equivalent Fahrenheit temperatures. You...

    python Write a program that displays a table of Celsius temperatures and equivalent Fahrenheit temperatures. You can find the formula online if necessary. Your program should print both scales accurate to one decimal place in columns 8 characters wide (see page 71). Use Celsius temperatures ranging from -40C to 40C in 10 degree increments. See Required Output. Required Output CEL FAH === -40.0 -40.0 -30.0 -22.0 -20.0 -4.0 - 10.0 14.0 0.0 32.0 10.0 50.0 20.0 68.0 30.0 86.0 40.0...

  • Java program Write a Temperature class that represents temperatures in degrees in both Celsius and Fahrenheit....

    Java program Write a Temperature class that represents temperatures in degrees in both Celsius and Fahrenheit. Use a floating- point number for the temperature and a character for the scale, eitherでfor Celsius or 'F' for fahrenheit. The class should have Four constructors: one for the number of degrees, one for the scale, one for both the degrees and scale, and a default constructor. For each of these constructors, assume zero degrees if no value is specified and celsius if no...

  • Question: Fahrenheit To Celsius Temperature Converter GUI Assignment Write A GUI To... java Fahrenholt to Celsius...

    Question: Fahrenheit To Celsius Temperature Converter GUI Assignment Write A GUI To... java Fahrenholt to Celsius Temperature Converter GUI Assignment Write a Gul to convert Fahrenheit temperatures to Celsius temperatures and has the following appearance: Com Convert It must include the following foatures • The frame we must say 'Fahrenheit to Celsius Temperature Converter • A border layout will be used for the GUI • The JLabelite of the GUI wil suy Fahrerholt to Celsius Temperature Converter and be in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT