title: Classes, Methods and Random Number Generating
body: <blockquote>
    <p>You will write a Java program to play the game of Pico, Fermi, Bagel.
    Here are the rules of the game:</p>
    
    <p>The computer will generate a "secret" three digit number at random.
    The first number will not be 0, and all the digits will be different.
    The user tries to guess the number. If the user guesses correctly,
    then the game is over.</p>
    
    <p>If not, the computer gives a hint and the player tries again.  The
    hints:</p>
    
    <ul>
    <li><p>for each digit that matches the secret number in the proper place, the computer prints "Fermi"</p></li>
    <li><p>for each digit that matches, but not in the proper place, the computer prints "Pico"</p></li>
    <li><p>if none of the digits match, the computer prints "Bagels"</p></li>
    </ul>
    
    <p>The program will have a main class and a Bagels class. The bagels
    class will call 3 other methods to</p>
    
    <ol>
    <li><p>generate the secret number</p></li>
    <li><p>determine whether the current guess is a winner</p></li>
    <li>evaluate the current guess and print hints</li>
    </ol>
  </blockquote>
  
  <p><strong>My Problem</strong> -- When I run the program, it asks me to enter a 3 digit code, but then it just keeps asking me to enter a 3 digit code instead of comparing the user's guess number to the random generated number. I'm assuming I'm doing something dumb with the classes or methods since we just learned them not too long ago and they still confuse me.</p>
  
  <p>The first part of the program is my main class, the second is the Bagels class.</p>
  
  <pre><code>package assignment.iii;
  import javax.swing.JOptionPane;
  import java.util.Scanner; 
  
  public class AssignmentIII {
  
  public static void main(String[] args) 
     {
     int playagain = JOptionPane.showConfirmDialog(null, "Would you like to play?", "Message", JOptionPane.YES_NO_OPTION);
  
      while (playagain == JOptionPane.YES_OPTION) {      
  
       Bagels myBagels = new Bagels();
       myBagels.playGame() ;     
       myBagels.randNumber = 0;
       playagain = JOptionPane.showConfirmDialog(null, "Would you like to play again?", "Message", JOptionPane.YES_NO_OPTION);
  }
  }
  }
  
  
  
   // start of Bagels class
  
  package assignment.iii;
  import java.util.Random;
  import javax.swing.JOptionPane;
  
  public class Bagels{
  
  
  public int randNumber; 
  private int Guess; 
  private int Rand1, Rand2, Rand3;
  private int Guess1, Guess2, Guess3;
  private int guessCount;
  
  
  public void playGame() 
  {
  
      do {
      Guess = Integer.parseInt(JOptionPane.showInputDialog("Enter a three digit number"));
      }
      while (Guess != randNumber);                   
  
   }
  
  private int generateSecretNumber()
  {
           Random randN = new Random();
           return randN.nextInt(999)+1; 
  }  
  
  private void printHint(String guess)        
  {
     if(randNumber == Guess)
          System.out.println("Correct");
  
        else
           {
           Guess1 = (Guess)/100;
           Guess2 = (Guess%100)/10;
           Guess3 = (Guess%100)%10;
           }
  
      if(Guess1 == Rand1)
      {
          System.out.println("Fermi");
      }
      if(Guess2 == Rand2)
      {
          System.out.println("Fermi");
      }
      if(Guess3 == Rand3 )
      {
          System.out.println("Fermi");
      }
      if(Guess2 == Rand1)
      {
          System.out.println("Pico");
      }
      if(Guess3 == Rand1)
      {
          System.out.println("Pico");
      }
      if(Guess1 == Rand2)
      {
          System.out.println("Pico");
      }
      if(Guess3 == Rand2)
      {
          System.out.println("Pico");
      }
      if(Guess1 == Rand3)
      {
          System.out.println("Pico");
      }
      if(Guess2 == Rand3)
      {
          System.out.println("Pico");
      }
      else if(Guess1 != Rand1 &amp;&amp; Guess1 != Rand2 &amp;&amp; Guess1 != Rand3 &amp;&amp;
              Guess2 != Rand1 &amp;&amp; Guess2 != Rand2 &amp;&amp; Guess2 != Rand3 &amp;&amp;
              Guess3 != Rand1 &amp;&amp; Guess3 != Rand2 &amp;&amp; Guess3 != Rand3)
      {
          System.out.println("Bagels");
      }
      guessCount++;
     }
  }
  </code></pre>