title: Java: Optimize code
body: <p>I've been working on this elevator program for quite some time now and finally finished it and made it work and I'm pretty proud of myself, but I'd like to see ways how to optimize my code so I can learn for the future. By optimizing I mean, making the code look better, maybe by using less lines of codes.</p>
  
  <pre><code>static int floor = 0, choice1, person = 0;
  
  public static void main(String args[])
  {
  
      floor = ((int) (Math.random() * 10 + 1));
  
      System.out.println("The elevator is now on floor " +floor);
      System.out.print("Which floor are you at now (0-10) where 0 = basement: ");
      choice1 = Keyboard.readInt();
  
      if(floor == choice1)
      {
          System.out.println("Enter the elevator");
      }
  
      else if(floor &gt; choice1)
      {
          ElevatorDown();
      }
  
      else if(floor &lt; choice1)
      {
          ElevatorUp();
      }
  
      System.out.println("To which floor would you want to go (0-10) where 0 = basement");
      choice1 = Keyboard.readInt();
  
      if(floor &gt; choice1)
      {
          ElevatorDown();
      }
  
      else if(floor &lt; choice1)
      {
          ElevatorUp();
      }
  
  }
  
  public static void ElevatorUp()
  {
      System.out.println("The elevator is on it's way up...");
  
      for (person = choice1; choice1&gt;=floor; floor++)
  
      System.out.println(floor);
  
      System.out.println("The elevator has arrived");
  }
  
  public static void ElevatorDown()
  {
      System.out.println("The elevator is on it's way down...");
      for (person = choice1; choice1&lt;=floor; floor--)
  
      System.out.println(floor);
  
      System.out.println("The elevator has arrived");
  }
  </code></pre>