Question

Q6: (Temperature Conversions) Implement the following integer methods: a) Method celsius returns the Celsius equivalent of a
solve using java
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java Program:

import java.util.*;

class TemperatureConversions
{
   //Main method
   public static void main(String args[])
   {
       char ch;
       int tempF, tempC;
      
       Scanner sc = new Scanner(System.in);
      
       //Loop till user wants to quit
       while(true)
       {
           //Displaying menu
           ch = displayMenu();
          
           switch(ch)
           {
               //Celsius to Fahrenheit
               case 'C':
              
                           System.out.print("\n Enter the Celsius temperature: ");
                           tempC = sc.nextInt();
                           tempF = CtoF(tempC);
                           System.out.print("\n The temperature " + tempC + " Celsius is " + tempF + " Fahrenheit. ");
                           break;
              
               //Fahrenheit to Celsius              
               case 'F':  
              
                           System.out.print("\n Enter the Fahrenheit temperature: ");
                           tempF = sc.nextInt();
                           tempC = FtoC(tempF);
                           System.out.print("\n The temperature " + tempF + " Fahrenheit is " + tempC + " Celsius. ");
                           break;
              
               //Quit
               case 'Q':   return;
              
               default:   break;
           }
       }
   }
  
   //Displaying menu
   public static char displayMenu()
   {
       Scanner sc = new Scanner(System.in);
       char ch;
      
       do
       {
           //Printing menu
           System.out.print("\n\n Please select one of the following: \n\t F - Fahrenheit to Celsius \n\t C - Celsius to Fahrenheit \n\t Q - Quit. \n\n\t Choice: ");
      
           //Accepting user input
           ch = ((sc.next()).toUpperCase()).charAt(0);
          
       }while(ch != 'F' && ch != 'C' && ch != 'Q');
      
       return ch;
   }
  
   //Celsius to Fahrenheit
   public static int CtoF(int c)
   {
       int tempF;
          
       //Converting temperature from Celsius to Fahrenheit
       tempF = (int)( c * (9/5.0)) + 32;
      
       return tempF;
   }
  
   //Fahrenheit to Celsius
   public static int FtoC(int f)
   {
       int tempC;
      
       //Converting temperature from Fahrenheit to Celsius
       tempC = (int)(( f - 32) * (5/9.0));
      
       return tempC;
   }
}

_______________________________________________________________________________________________________

Sample Run:

GAN C:\Windows\system32\cmd.exe D:\Java>javac TemperatureConversions.java D:\Java>java TemperatureConversions Please select o

Add a comment
Know the answer?
Add Answer to:
solve using java Q6: (Temperature Conversions) Implement the following integer methods: a) Method celsius returns the...
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
  • 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*...

  • Process Create a City structure. The structure will hold the name of a city and its temperature. ...

    using C Process Create a City structure. The structure will hold the name of a city and its temperature. In the main function, read in a series of city names and their temperature expressed in Fahrenheit. Store the data in an array of City structures. Stop reading when either: The user enters the word "quit" for a city name, or The size of the array is about to be exceeded. Create a function that determines the highest temperature of the...

  • Write a program in java (consists of three files) that uses class-objects to calculate temperature in...

    Write a program in java (consists of three files) that uses class-objects to calculate temperature in Fahrenheit and Centigrade. That is, there are at least three classes. The problem is to write a three classes (3) that calculate the temperature either in Fahrenheit or Celsius. This action should be repeatable. This demonstrates use of a menu to give user a choice. Use of proper syntax for named constants, variables, reference variables, constructors, getter and setter and display methods is expected....

  • Using Java IDE Write a recursive method which takes an integer number and returns the sum...

    Using Java IDE Write a recursive method which takes an integer number and returns the sum of the numbers from 1 to that number. The method must solve the problem recursively.Then write an application which calls the method with a few different numbers and displays the return value of the method.

  • Java please The kelvin is the base unit of temperature in the International System of Units...

    Java please The kelvin is the base unit of temperature in the International System of Units (SI), having the unit symbol K. It is named after the Belfast-born, Glasgow University engineer and physicist William Thomson, 1st Baron Kelvin (1824–1907). It uses absolute zero as its null point. The Celsius scale, also known as the centigrade scale, is a temperature scale used by the International System of Units (SI). The Celsius scale is based on 0 °C for the freezing point...

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

  • WRITING METHODS 1. Implement a method named surface that accepts 3 integer parameters named width, length,...

    WRITING METHODS 1. Implement a method named surface that accepts 3 integer parameters named width, length, and depth. It will return the total surface area (6 sides) of the rectangular box it represents. 2. Implement a method named rightTriangle that accepts 2 double arameters named sideA and hypotenuseB. The method will return the length of the third side. NOTE To test, you should put all of these methods into a ‘MyMethods’ class and then write an application that will instantiate...

  • C# Design and implement a program (name it PalindromeInteger), to check if an integer value is...

    C# Design and implement a program (name it PalindromeInteger), to check if an integer value is a palindrome or not, using 2 methods (reverse and isPalindrome) specified as follows: Method reverse(int number) takes integer number and returns number in reverse order. The method mathematically reverses the number. Method isPalindrome(int number) takes integer number and returns true if the number is palindrome; false otherwise. Use method reverse() to implement method isPalindrome(). Notice that an integer value is palindrome if the value...

  • C++ Design and implement a program (name it PalindromeInteger), to check if an integer value is...

    C++ Design and implement a program (name it PalindromeInteger), to check if an integer value is a palindrome or not, using 2 methods (reverse and isPalindrome) specified as follows: Method reverse(int number) takes integer number and returns number in reverse order. The method mathematically reverses the number. Method isPalindrome(int number) takes integer number and returns true if the number is palindrome; false otherwise. Use method reverse() to implement method isPalindrome(). Notice that an integer value is palindrome if the value...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

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