title: Converting Units using if statements?
body: <p>I have to write a program to convert between linear units in, ft, mi, mm, cm, m, km. I know there are easier and better ways to do this. I think we'ere just trying to fully understand if else if statements. But this is what I have so far. I'm just trying to figure out if I am on the right track. I've tried to write out some pseudocode but it just seems like a lot going on so I find it a bit overwhelming. Next I'm going to add a method to convert form in or mm to whatever is selected by the user.</p>
  
  <p>When I test the program i get this: UnitConversion@76c5a2f7 (EDIT: THIS ISSUE WAS FIXED)
  Ok I made the suggested changes and that allowed the first part of the program to run properly. I have now added my second method to convert from in/mm to the other measurements.. I was having issues but I figured it out.</p>
  
  <p>Here is my main method;</p>
  
  <pre><code>public class LinearConversion 
  {
      public static void main(String[] args)
      {
          UnitConversion newConvert = new UnitConversion("km", "m", 100);
  
          System.out.println(newConvert);
      }
  }
  </code></pre>
  
  <p>Any suggestions? What am I missing or not understanding about doing this sort of program?</p>
  
  <pre><code>    public class UnitConversion 
  {
  
      private String input;
      private String output;
      private double value;
      private double temp;
  
      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;
      }
  
      public String toString()
      {
          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 value + input + " " + output;
      }
  
       public double getUnit()
      {
          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 
              {
                  System.out.println(in + "in");
              }  
          }
          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 
              {
                  System.out.println(mm + "mm");
              }
          }
  }
  </code></pre>