title: Unit Conversion Program - How to get a variable from one method to another?
body: <p>I'm sure that there are better/easier ways to write this code, but I am only a few weeks into learning to program and the purpose is to use if/else if/else statements. What I am trying to do is take a value and unit of measure and then convert it to another unit of measure.</p>
  
  <p>The first method: <code>getSmallestUnit</code> is supposed to convert any input into the smallest unit either inches or millimeters.</p>
  
  <p>The second method: <code>getNewUnitConversion</code> is supposed then take the new value and convert it into the correct unit.</p>
  
  <p>I'm not sure how to get the variable in and mm into the <code>getNewUnitConversion</code>.</p>
  
  <p>When I run the program it just prints out the value for the constant example converting from 1m to ft it prints <code>0.00328084ft</code>;</p>
  
  <pre><code>import java.util.Scanner;
  
  public class LinearConversion 
  {
      //==================MAIN================
      public static void main(String[] args)
      {
          Scanner newConversion = new Scanner(System.in);
          System.out.print("Enter a linear unit to convert from: ");
          String fromUnit = newConversion.next();
  
          System.out.print("Enter a linear unit to convert to: ");
          String toUnit = newConversion.next();
  
          System.out.print("Enter a value: ");
          double value = newConversion.nextDouble();
  
          UnitConversion timsConversion = new UnitConversion(fromUnit, toUnit, value);
  
          timsConversion.getSmallestUnit();
  
          double conversion = timsConversion.getNewUnitConversion();
          System.out.println(conversion);
  
      }
  }
  
  
  public class UnitConversion 
  {
  
      private String input;
      private String output;
      private double value;
  
      private double in, ft, mi, mm, cm, m, km;
      private final double inch_feet = 12;
      private final double inch_miles = 63360;
  
  
      private final double inch_millimeters = 25.4;
      private final double inch_centimeters = 2.54;
      private final double inch_meters = 0.0254;
      private final double inch_kilometers = 0.0000254;
  
      private final double millimeters_inch = 0.0393701;
      private final double millimeters_feet = 0.00328084;
      private final double millimeters_miles = 0.000000622;
  
      private final double millimeter_centimeters = 10;
      private final double millimeter_meters = 1000;
      private final double millimeter_kilometers = 1000000;
  
      public UnitConversion(String in, String out, double val)
      {
          input = in;
          output = out;
          value = val;
      }
  
      //Convert units to convert from (input) to its smallest form either in or mm
      public double getSmallestUnit()
      {
          if (input.equals("mi"))
          {
              in = value * inch_miles; 
              input = "in";
          }
  
          else if (input.equals("ft"))
          {
              in = value * inch_feet;
              input = "in";
          }
  
          else
          {
              in = value;
              input = "in";
          }
  
          if (input.equals("km"))
          {
              mm = value * millimeter_kilometers;
              input = "mm";
          }
  
          else if (input.equals("m"))
          {
              mm = value * millimeter_meters;
              input = "mm";
          }
  
          else if (input.equals("cm"))
          {
              mm = value * millimeter_centimeters;
              input = "mm";
          }
  
          else
          {
              mm = value;
              input = "mm";
          }
          return 0;
      }
  
      //Convert in or mm to desired unit of measurement
       public double getNewUnitConversion()
      {
          //convert from english standard
          if (input.equals("in"))
          {
              if (output.equals("ft"))
              {
                  ft = in * inch_feet;
                  System.out.println(ft + "ft");
              }
              else if (output.equals("mi"))
              {
                  mi = in * inch_miles;
                  System.out.println(mi + "mi");
              }
              else if (output.equals("mm"))
              {
                  mm = in * inch_millimeters;
                  System.out.println(mm + "mm");
              }
              else if (output.equals("cm"))
              {
                  cm = in * inch_centimeters;
                  System.out.println(cm + "cm");
              }
              else if (output.equals("m"))
              {
                  m = in * inch_meters;
                  System.out.println(m + "m");
              }
              else if (output.equals("km"))
              {
                  km = in * inch_kilometers;
                  System.out.println(km + "km");
              }  
              else if (output.equals("in"))
              {
                  System.out.println(in + "in");
              }  
              else 
              {
                  System.out.println("Error: Must enter linear unit of measure in, ft, mi, mm, cm, m, or km");
              }
          }
          //convert from metric
          else
          {
              if (output.equals("cm"))
              {
                  cm = mm * millimeter_centimeters;
                  System.out.println(cm + "cm");
              }
              else if (output.equals("m"))
              {
                  m = mm * millimeter_meters;
                  System.out.println(m + "m");
              }
              else if (output.equals("km"))
              {
                  km = mm * millimeter_kilometers;
                  System.out.println(km + "km");
              }
              else if (output.equals("in"))
              {
                  in = mm * millimeters_inch;
                  System.out.println(in + "in");
              }
              else if (output.equals("ft"))
              {
                  ft = mm * millimeters_feet;
                  System.out.println(ft + "ft");
              }
              else if (output.equals("mi"))
              {
                  mi = mm * millimeters_miles;
                  System.out.println(mi + "mi");
              }
              else if (output.equals("mm"))
              {
                  System.out.println(mm + "mm");
              }
              else 
              {
                  System.out.println("Error: Must enter linear unit of measure in, ft, mi, mm, cm, m, or km");
              }
          }
          return 0;
      }
  }
  </code></pre>