title: Java DigitExtractor
body: <p>I'm having trouble with an assignment that I'm working on. Here is the prompt:</p>
  
  <p>Create a DigitExtractor application that prompts the user for an integer (in the range: 0-999) and then displays either the ones, tens, or hundreds digit of the number. The user will select from a menu which digit they wish to display.</p>
  
  <p>This program needs to be written as a class.  The menu will be your driver program that you submit with the class so your instructor can use it to test the class.  </p>
  
  <p>Here is my code for it:</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  public class TestingMenu
  {
      public int number;
      public int units;
      public int tens;
      public int hundreds;
  
      public TestingMenu(int input)
      {
          number = input;
          units = number%10;
  
          tens = number%10;
  
          hundreds = number%10;
      }
  
      public int return_units()
      {
          return units;
      } 
  
      public int return_tens()
      {
          return tens;
      }
  
      public int return_hundreds()
      {
          return hundreds;
      }
  
      public static void main(String[] args)
      {
          Scanner kbReader = new Scanner(System.in);
          TestingMenu num;
          int choice;
  
          int input;
          do
          {
              System.out.print("Enter a number(0-999): ");
              input = kbReader.nextInt();
              System.out.println("");
              System.out.println("Options");
              System.out.println("1) Units");
              System.out.println("2) Tens");
              System.out.println("3) Hundreds");
              System.out.println("4) Quit");
              num = new TestingMenu(input);
              System.out.print("Enter your choice: ");
              choice = kbReader.nextInt();
  
              switch(choice)
              {
                  case 1: 
                  System.out.println("The units digit is: " + num.return_units());
                  break;
  
                  case 2: 
                  System.out.println("The tens digit is: " + num.return_tens());
                  break;
  
                  case 3: System.out.println("The hundreds digit is: " + num.return_hundreds());
                  break;
  
                  case 4: 
                  System.exit(4);
                  break;
  
                   default: 
                   System.out.print("Invalid. Select a number from the given options.");
                   choice = kbReader.nextInt();
               }
          }
          while(choice != 4);
      }
  }
  </code></pre>
  
  <p>I think I've almost got it, but I'm having issues whenever I test it. When I input a number such as 987 and I run all the options from 1-3, I keep getting 7 for the ones, tens, and hundreds. 4 exits the program and works okay, but I've tested this numerous times. Overall, it seems to only print the last digit.</p>
  
  <p>Enter a number(0-999): 987</p>
  
  <p>Options 
  1) Units
  2) Tens
  3) Hundreds
  4) Quit
  Enter your choice: 1
  The units digit is: 7
  Enter a number(0-999): 987</p>
  
  <p>Options
  1) Units
  2) Tens
  3) Hundreds
  4) Quit
  Enter your choice: 2
  The tens digit is: 7
  Enter a number(0-999): 987</p>
  
  <p>Options
  1) Units
  2) Tens
  3) Hundreds
  4) Quit
  Enter your choice: 3
  The hundreds digit is: 7
  Enter a number(0-999): 987</p>
  
  <p>Options
  1) Units
  2) Tens
  3) Hundreds
  4) Quit
  Enter your choice: 4</p>
  
  <p>Could someone help me identify the error? I don't really know what went wrong with this program despite working on it for a few hours. Thanks in advance. All the help and feedback is greatly appreciated.</p>