Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USE LOOPS, DECIMAL FORMATTER FOR THIS JAVA PROGRAM Write a program that displays

ID: 3812700 • Letter: U

Question

USE LOOPS, DECIMAL FORMATTER FOR THIS JAVA PROGRAM

Write a program that displays a table of the Celsius temperatures requested by the user and their Fahrenheit equivalents. The program should accept as input the minimum Celsius value to be outputted in the table and the maximum Celsius value to be outputted in the table.

Input validation should be performed to make sure that the minimum Celsius value is between 5 and 10, and that the maximum Celsius value is between 20 and 100.

The formula for converting a tempertaure from Celsius to Fahrenheit is: F = 9/5 X Celsius + 32

Sample output upon execution should look something like this:

Enter the minimum Celsius tempertaure (between 5 and 10):

8

Enter the maximum Celsius temperature (between 20 and 100):

25

Celsius Fahrenheit

8.0 46.4

9.0 48.2

10.0 50.0

11.0 51.8

12.0 53.6

13.0 55.4

14.0 57.2

15.0 59.0

16.0 60.8

17.0 62.6

18.0 64.4

19.0 66.2

20.0 68.0

21.0 69.8

22.0 71.6

23.0 73.4

24.0 75.2

25.0 77.0

Process completed

Explanation / Answer

TempTest.java


import java.text.DecimalFormat;
import java.util.Scanner;

public class TempTest {

  
   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       System.out.println("Enter the minimum Celsius tempertaure (between 5 and 10): ");
       int minC = scan.nextInt();
       while( minC < 5 || minC > 10) {
           System.out.println("Invalid Input.");
           System.out.println("Enter the minimum Celsius tempertaure (between 5 and 10): ");
           minC = scan.nextInt();
       }
       System.out.println("Enter the maximum Celsius temperature (between 20 and 100): ");
       int maxC = scan.nextInt();
       while( maxC < 20 || maxC > 100) {
           System.out.println("Invalid Input.");
           System.out.println("Enter the maximum Celsius temperature (between 20 and 100): ");
           maxC = scan.nextInt();
       }
       DecimalFormat df = new DecimalFormat("0.0");
       System.out.println("Celsius Fahrenheit");
       for(int c=minC; c<=maxC; c++){
           double f = (9 * c ) /(double)5 + 32;
           System.out.println(df.format(c)+" "+df.format(f));
       }
       System.out.println("Process completed");

   }

}

Output:

Enter the minimum Celsius tempertaure (between 5 and 10):
8
Enter the maximum Celsius temperature (between 20 and 100):
25
Celsius   Fahrenheit
8.0   46.4
9.0   48.2
10.0   50.0
11.0   51.8
12.0   53.6
13.0   55.4
14.0   57.2
15.0   59.0
16.0   60.8
17.0   62.6
18.0   64.4
19.0   66.2
20.0   68.0
21.0   69.8
22.0   71.6
23.0   73.4
24.0   75.2
25.0   77.0
Process completed