java unit converter source code

Solutions on MaxInterview for java unit converter source code by the best coders in the world

showing results for - "java unit converter source code"
Stefano
10 Jan 2018
1import java.util.Scanner;
2
3/**
4   This class converts between two units.
5*/
6public class ConversionCalculator
7{
8   public static void main(String[] args)
9   {
10      Scanner in = new Scanner(System.in);
11      
12      System.out.println("Convert from:");
13      String fromUnit = in.nextLine();
14
15      System.out.println("Convert to: ");
16      String toUnit = in.nextLine();
17      
18      UnitConverter from = new UnitConverter(fromUnit);
19      UnitConverter to = new UnitConverter(toUnit);
20
21      System.out.println("Value:");
22      double val = in.nextDouble();
23
24      double meters = from.toMeters(val);
25      double converted = to.fromMeters(meters);
26
27      System.out.println(val + " " + fromUnit + " = " + converted + " " + toUnit);
28   }
29}