Question
You are allowed to import the scanner and math methods. Not allowed to use the var variable
Solution Description TemperatureConverter A formula for converting temperature in Kelvin to degrees Fahrenheit is as follows: Fahrenheit Kelvin(9/5)-459.67 Your goal for this assignment is to write one file, TemperatureConverter.java, which prompts the user for a temperature in Kelvin, converts the temperature to degrees Fahrenheit, and then outputs the results by printing it to the terminal. Note that the temperature provided by the user may or may not have a decimal value (e.g. 42 and 3.14159 are both valid inputs). The converted result that you output should be rounded to two decimal places (e.g. 2->2.00, 28.1231 -> 28.12). You may assume that the user will enter a valid number when prompted for a temperature. Below is an example of the way a user would interact with your program. Be sure to follow the syntax exactly. Note that each execution ends with a newline character (after Fahrenheit), and that the temperature in Kelvin is identical to the input when it is printed back to the console. java TemperatureConverter Enter a temperature in Kelvin: 291.2359 291.2359 Kelvin is 64.55 degrees Fahrenheit $ java TemperatureConverter Enter a temperature in Kelvin: 278.706 278.706 Kelvin is 42.00 degrees Fahrenheit
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.io.*;
import java.text.DecimalFormat;

public class TemperatureConverter
{
   public static void main(String[] args) throws IOException {
       System.out.print("Enter a temperature in Kelvin: ");
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       double temperatureInKelvin = Double.parseDouble(br.readLine());
       double result = convertToFahrenheit(temperatureInKelvin);
       System.out.println("\n" + temperatureInKelvin + " Kelvin is " + roundToTwoDecimalPlaces(result) + " degrees Fahrenheit");
   }
  
   public static double convertToFahrenheit(double temperatureInKelvin)
   {
   double convertedTemperature = (((temperatureInKelvin - 273) * 9/5) + 32);
   return convertedTemperature;
   }
  
   public static double roundToTwoDecimalPlaces(double value)
   {
   DecimalFormat df = new DecimalFormat("#.##");
value = Double.valueOf(df.format(value));
return value;
   }
}

NOTE: Please save the code in a file and name the file as "TemperatureConverter.java".

Add a comment
Know the answer?
Add Answer to:
You are allowed to import the scanner and math methods. Not allowed to use the var...
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
  • Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete...

    Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete programs using two classes: client and supplier 2   User Interface Specification This is a console-based I/O program. Display should go to System.out (print or println) and the program will get user input using the Scanner class. The flow of execution should be as follows: When the program starts, display a one-line introduction to the user Display a menu with 5 options 1. validate zip...

  • In this project you will create a console C++ program that will have the user to...

    In this project you will create a console C++ program that will have the user to enter Celsius temperature readings for anywhere between 1 and 365 days and store them in a dynamically allocated array, then display a report showing both the Celsius and Fahrenheit temperatures for each day entered. This program will require the use of pointers and dynamic memory allocation. Getting and Storing User Input: For this you will ask the user how many days’ worth of temperature...

  • Chapter 9 Lab Text Processing and Wrapper Classes Lab Objectives ? Use methods of the Character...

    Chapter 9 Lab Text Processing and Wrapper Classes Lab Objectives ? Use methods of the Character class and String class to process text ? Be able to use the StringTokenizer and StringBuffer classes Introduction In this lab we ask the user to enter a time in military time (24 hours). The program will convert and display the equivalent conventional time (12 hour with AM or PM) for each entry if it is a valid military time. An error message will...

  • Capitalization JAVA In this program, you will read a file line-by-line. For each line of data...

    Capitalization JAVA In this program, you will read a file line-by-line. For each line of data (a string), you will process the words (or tokens) of that line one at a time. Your program will capitalize each word and print them to the screen separated by a single space. You will then print a single linefeed (i.e., newline character) after processing each line – thus your program will maintain the same line breaks as the input file. Your program should...

  • In Java please Only use methods in the purpose. Thank you The purpose of this assignment is to help you learn Java iden...

    In Java please Only use methods in the purpose. Thank you The purpose of this assignment is to help you learn Java identifiers, assignments, input/output nested if and if/else statements, switch statements and non-nested loops. Purpose Question 2-String variables/Selection & loops. (8.5 points) Write a complete Java program which prompts the user for a sentence on one line where each word is separated by one space, reads the line into one String variable using nextline), converts the string into Ubbi...

  • language is java Restrictions: You are not allowed to use anything from the String, StringBuilder, or...

    language is java Restrictions: You are not allowed to use anything from the String, StringBuilder, or Wrapper classes. In general, you may not use anything from any other Java classes, unless otherwise specified. You are not allowed to use String literals in your code ("this is a string literal"). You are not allowed to use String objects in your code. The methods must be implemented by manipulating the data field array, The CSString Class: NOTE: Pay very careful attention to...

  • Java This assignment will give you practice with line based file processing and scanner methods. Modify...

    Java This assignment will give you practice with line based file processing and scanner methods. Modify the Hours program we did in class. You are going to write a program that allows the user to search for a person by ID. Your program is required to exactly reproduce the format and behavior of the log of execution as follows: Enter an ID: 456 Brad worked 36.8 hours (7.36 hours/day) Do you want to search again? y Enter an ID: 293...

  • Programming Assignment 6: A Python Class, Attributes, Methods, and Objects Obiectives .Be able to...

    I need some help with programming this assignment. Programming Assignment 6: A Python Class, Attributes, Methods, and Objects Obiectives .Be able to write a Python class Be able to define class attributes Be able to define class methods .Be able to process input from a text file .Be able to write an application using objects The goal of this programming assignment is to develop a simple image processing application. The application will import a class that creates image objects with...

  • This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named...

    This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named Budgeter.java. To use a Scanner for console input, you must import java.util.*; in your code. This program prompts a person for income and expense amounts, then calculates their net monthly income. Below are two example logs of execution from the program. This program’s behavior is dependent on the user input (user input is bold and underlined below to make it stand out and differentiate...

  • !!!!!!!Java!!!!! When you are confident that your methods work properly and that you can generate random...

    !!!!!!!Java!!!!! When you are confident that your methods work properly and that you can generate random text with my generateText method, you can move on to the second step. Create a third class called Generator within the cs1410 package. Make class. This class should have a main method that provides a user interface for random text generation. Your interface should work as follows: Main should bring up an input dialog with which the user can enter the desired analysis level...

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