Question

In: Computer Science

Write a JAVA program that displays a table of the Celsius temperatures and their Fahrenheit equivalents....

Write a JAVA program that displays a table of the Celsius temperatures and their Fahrenheit
equivalents.
 The formula for converting a temperature from Celsius to Fahrenheit is
F = 9/ 5 C + 32
where F → Fahrenheit temperature
C → Celsius temperature.
 Allow the user to enter the range of temperatures in Celsius to be converted into Fahrenheit.
 Your program must use a loop to display the values of the temperature conversions (see sample
output).


Sample Output:
Welcome to the Temperature Converter!! Enter the range of temperatures in Celsius to be converted into
Fahrenheit
Enter minimum temperature in Celsius:
­5
Enter maximum temperature in Celsius:
7
The corresponding Fahrenheit equivalents are:
­5.0 C 23.0 F
­4.0 C 24.8 F
­3.0 C 26.6 F
­2.0 C 28.4 F
­1.0 C 30.2 F
0.0 C 32.0 F
1.0 C 33.8 F
2.0 C 35.6 F
3.0 C 37.4 F
4.0 C 39.2 F
5.0 C 41.0 F
6.0 C 42.8 F
7.0 C 44.6 F
Goodbye!

Solutions

Expert Solution

Algorithm to display Celsius temperatures and their Fahrenheit equivalents

1.Input mintemp from user.

2.Input maxterm from user.

3.Implement a for loop from i=minterm to maxterm

    3.1) Calculate ((9*i)/5)+32 and store result in variable fah.

    3.2) Print i,fah

Java program to implement above algorithm

import java.util.*;

public class Main
{
        public static void main(String[] args) {
        
        double mintemp,maxtemp,fah;  //declaring variables
        Scanner sc=new Scanner(System.in); //calling scanner class
        
    System.out.println("Welcome to the Temperature Converter!! Enter the range of temperatures in Celsius to be converted into Fahrenheit");

    System.out.println("Enter minimum temperature in Celsius:"); 
    mintemp=sc.nextDouble(); //taking minimum temperature in Celsius
    System.out.println("Enter maximum temperature in Celsius:"); 
    maxtemp=sc.nextDouble(); //taking maximum temperature in Celsius
    double i;
    
    System.out.println("The corresponding Fahrenheit equivalents are");
    for(i=mintemp;i<=maxtemp;i++) //implementing for loop for range of temperature
    {
        fah=((9*i)/5)+32; //converting temperature into Fahrenheit
        System.out.println(i+"C "+fah+" F"); //printing Celsius temperature and converted Fahrenheit temperature
    }
    
        }
}

Output of above code is:


Related Solutions

Write a program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The...
Write a program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The table should include rows for all temperatures between 0 and 100 degrees Celsius that are multiples of 10 degrees Celsius. Include appropriate headings on your columns. The formula for converting between degrees Celsius and degrees Fahrenheit can be found on the internet. Python 3
Write a java program to convert Celsius degrees to Fahrenheit degrees the user enters degrees in...
Write a java program to convert Celsius degrees to Fahrenheit degrees the user enters degrees in Celsius and the program Coverts the input to Fahrenheit using the following formula T(°F) = T(°C) × 1.8 + 32 submit the source code Design output Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
At what temperatures values are the following scales the same? (a) The Fahrenheit and the Celsius   ...
At what temperatures values are the following scales the same? (a) The Fahrenheit and the Celsius    (b) The Celsius and the Kelvin     (c) The Fahrenheit and the Kelvin  
Instructions Write a program in C# that converts a temperature given in Fahrenheit to Celsius. Allow...
Instructions Write a program in C# that converts a temperature given in Fahrenheit to Celsius. Allow the user to enter values for the original Fahrenheit value. Display the original temperature and the formatted converted value. Use appropriate value returning methods for entering (input), calculating, and outputting results.
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text...
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text label and a button.When the program begins, the label displays a 0. Then each time the button is clicked, the number increases its value by 1; that is each time the user clicks the button the label displays 1,2,3,4............and so on.
in java Write a program that reads in ten numbers and displays the number of distinct...
in java Write a program that reads in ten numbers and displays the number of distinct numbers and the distinct numbers separated by exactly one space (i.e., if a number appears multiple times, it is displayed only once). (Hint: Read a number and store it to an array if it is new. If the number is already in the array, ignore it.) After the input, the array contains the distinct numbers. Here is the sample run of the program: Enter...
In Java: Write a program called F2C that allows the user to convert from degrees Fahrenheit...
In Java: Write a program called F2C that allows the user to convert from degrees Fahrenheit to degrees Celsius. The program should prompt for a temperature in Fahrenheit and output a temperature in Celsius. All calculations should be done in in ints, so be careful of truncation.
Part 1:Write a program in Java that declares an array of 5 elements and displays the...
Part 1:Write a program in Java that declares an array of 5 elements and displays the contents of the array. Your program should attempt to access the 6th element in the array (which does not exist) and using try. catch your program should prevent the run-time error and display your error message to the user. The sample output including the error message is provided below. Part (1) Printing an element out of bounds 5 7 11 3 0 You went...
Java Write a program that displays all the numbers from 100 to 200 that are divisible...
Java Write a program that displays all the numbers from 100 to 200 that are divisible by 5 or 6, but not both Make sure all instructions and outputs for the user are explicit
Write a Java program which reads a positive integer from the command line, then displays the...
Write a Java program which reads a positive integer from the command line, then displays the sum of all even values up to and including the value provided, followed by the sum of all odd values up to and including the value provided. validate that the command line argument is an integer greater than 0 to validate the type, you can use Integer.parseInt() with a try/catch for NumberFormatException use one or more for loops to perform the even and odd...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT