Answers for "java unit converter source code"

0

java unit converter source code

import java.util.Scanner;

/**
   This class converts between two units.
*/
public class ConversionCalculator
{
   public static void main(String[] args)
   {
      Scanner in = new Scanner(System.in);
      
      System.out.println("Convert from:");
      String fromUnit = in.nextLine();

      System.out.println("Convert to: ");
      String toUnit = in.nextLine();
      
      UnitConverter from = new UnitConverter(fromUnit);
      UnitConverter to = new UnitConverter(toUnit);

      System.out.println("Value:");
      double val = in.nextDouble();

      double meters = from.toMeters(val);
      double converted = to.fromMeters(meters);

      System.out.println(val + " " + fromUnit + " = " + converted + " " + toUnit);
   }
}
Posted by: Guest on September-15-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language