TizzyT

WorldTemperatureTableCalculator -TizzyT

Feb 16th, 2016
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.82 KB | None | 0 0
  1. package worldtemperaturetablecalculator;
  2. import java.util.Scanner;
  3. public class WorldTemperatureTableCalculator {
  4.     public static void main(String[] args) {
  5.         // The multiplier used in conversion formula
  6.         final double Multiplier = 1.8;
  7.        
  8.         // The offset used in conversion formula
  9.         final double Offset = 32;
  10.        
  11.         // Scanner to obtain user inputs
  12.         Scanner Inputs = new Scanner(System.in);    
  13.  
  14.         // Ask the user what city
  15.         System.out.println("What city do you live in?");
  16.                
  17.         // String to store city information
  18.         String City = Inputs.nextLine();
  19.  
  20.         // Asks the user what is the temperature in Celsius there
  21.         System.out.println("Enter a starting temperature in Celsius:");
  22.        
  23.         // double to store initial degrees Celsius
  24.         int Celsius = (int)Inputs.nextDouble();
  25.  
  26.         // Closes the scanner
  27.         Inputs.close();
  28.        
  29.         // Output the resulting conversion along with city
  30.         System.out.printf("Temperature Conversion Table for %s:%n%n" +
  31.                           "%-18sFahrenheit%n" , City, "Celsius");
  32.        
  33.         // Integer to specify limit of loop (counter)
  34.         int Range = Celsius + 20;
  35.        
  36.         // Double to store resulting Fahrenheit conversions
  37.         double Fahrenheit;
  38.        
  39.         // Convert and print 20 following temperatures (inclusive)
  40.         for (int i = Celsius; i < Range; i++)
  41.         {
  42.             // Do Celsius to Fahrenheith convertion for current i
  43.             Fahrenheit = (Multiplier * i) + Offset;
  44.            
  45.             // Print Celsius as integer and Fahrenheit to 1 decimal point
  46.             System.out.printf("%-18d%.1f%n", i, Fahrenheit);
  47.         }
  48.     } // End of main()
  49. } // End of WorldTemperatureTableCalculator class
Advertisement
Add Comment
Please, Sign In to add comment