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.

  • For this assignment you will create a program converting Fahrenheit temperatures to Celsius temperatures. The formula...

    For this assignment you will create a program converting Fahrenheit temperatures to Celsius temperatures. The formula for converting a temperature from Celsius to Fahrenheit is: F = C x 1.8 + 32, where F is the Fahrenheit temperature and C is the Celsius temperature. Write a function named Fahrenheit that accepts a Celsius temperature as an argument and returns the temperature converted to Fahrenheit. Demonstrate the function by accepting a Celsius temperature from a user and displaying the temperature converted...

  • 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*...

  • (in python) Write a GUI application that converts Celsius temperatures to Fahrenheit temperatures. The user s......

    (in python) Write a GUI application that converts Celsius temperatures to Fahrenheit temperatures. The user s... Write a GUI application that converts Celsius temperatures to Fahrenheit temperatures. The user should be able to enter a Celsius temperature, click a button, and then see the equivalent Fahrenheit temperature. Use the following formula to make the conversion ( F=9/5 C + 32) where F is the Fahrenheit temperature and C is the Celsius temperature

  • 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

  • IN JAVA…Write a GUI application that converts Celsius temperatures to Fahrenheit temperatures. The user should be...

    IN JAVA…Write a GUI application that converts Celsius temperatures to Fahrenheit temperatures. The user should be able to enter a Celsius temperature, click a button, and then see the equiva-lent Fahrenheit temperature. Use the following formula to make the conversion: F = (9/5)C + 32 F is the Fahrenheit temperature and C is the Celsius temperature. Instead of only converting from Celsius to Fahrenheit, also convert from Fahrenheit to Celsius depending on the user's choice. Some hints: Use JTextField and...

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