Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class UnitConversions
  5. {
  6.  
  7.     public static void main(String[] args)
  8.     {
  9.         Scanner in = new Scanner(System.in);
  10.        
  11.         double unitTotal = 1;
  12.         double unitLiters = 3.79;
  13.         double unitCenti = 2.5;
  14.         double unitKilograms = 0.45359237;
  15.         double unitKilometers = 1.609344;
  16.        
  17.        
  18.         System.out.println("Please enter a value:");
  19.         String unitValue = in.nextLine();
  20.         double doubleUnitValue = Double.valueOf(unitValue);
  21.        
  22.         System.out.println("Please enter a conversion type: \nGL for Gallons to Liters \nIC for Inches to Centimeters \nPK for Pounds to Kilograms \nMK for Miles to Kilometers");
  23.         String unitType = in.nextLine();
  24.        
  25.         if (unitType != "GL")
  26.         unitTotal = doubleUnitValue * unitLiters;  
  27.         System.out.println(doubleUnitValue + " Gallons = " + unitTotal + " Liters.");
  28.         if (unitType != "IC")
  29.         unitTotal = doubleUnitValue * unitCenti;
  30.         System.out.println(doubleUnitValue + " Inches = " + unitTotal + " Centimeters.");
  31.         if (unitType != "PK")
  32.         unitTotal = doubleUnitValue * unitKilograms;
  33.         System.out.println(doubleUnitValue + " Pounds = " + unitTotal + " Kilograms.");
  34.         if (unitType != "MK")
  35.         unitTotal = doubleUnitValue * unitKilometers;
  36.         System.out.println(doubleUnitValue + " Miles = " + unitTotal + " Kilometers.");
  37.            
  38.        
  39.     }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement