TizzyT

CtoF Assignment -TizzyT

Jan 28th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. /* Thien Huynh
  2.    01/28/2016
  3.    World Temperature Calculator
  4.    Converts degrees Celsius to degrees Fahrenheit */
  5.  
  6. package worldtemperaturecalculator;
  7. import java.util.Scanner;
  8.  
  9. public class WorldTemperatureCalculator {
  10.  
  11.     public static void main(String[] args) {
  12.         // The multiplier used in conversion formula
  13.         final double Multiplier = 1.8;
  14.        
  15.         // The offset used in conversion formula
  16.         final double Offset = 32;
  17.        
  18.         // String to store city information
  19.         String City;
  20.        
  21.         // double to store initial degrees Celsius
  22.         double Celsius;
  23.        
  24.         // double to store resulting Fahrenheit conversion
  25.         double Fahrenheit;
  26.        
  27.         // Scanner to obtain user inputs
  28.         Scanner Inputs = new Scanner(System.in);    
  29.  
  30.         // Ask the user what city
  31.         System.out.println("What city do you live in?");
  32.        
  33.         // Store user input into the String City
  34.         City = Inputs.nextLine();
  35.        
  36.         // Asks the user what is the temperature in Celsius there
  37.         System.out.println("What is the temperature in Celsius there?");
  38.        
  39.         // Stores the temperature in the double Celsius
  40.         Celsius = Inputs.nextDouble();
  41.        
  42.         // Calculate to Fahrenheit and store into the double Fahrenheit
  43.         Fahrenheit = (Multiplier * Celsius) + Offset;
  44.        
  45.         // Closes the scanner
  46.         Inputs.close();
  47.        
  48.         // Output the resulting conversion along with city
  49.         System.out.println("The current temperature in " + City + " is " +
  50.                             Celsius + " ⁰C, which is " + Fahrenheit + " ⁰F");
  51.        
  52.     } // End of main()
  53.  
  54. } // End of WorldTemperatureCalculator class
Advertisement
Add Comment
Please, Sign In to add comment