// TS8802 Project by John Phillips on 6/24/2003 last revised 6/26/2003

public class BinToOct extends Problem {
  
  public BinToOct()
  {
    newProblem();
  }

  public void newProblem()
  {
    int decNum = ( int ) ( Math.random() * 127 );
    String binNum = Integer.toString( decNum, 2 );
    String octNum = Integer.toString( decNum, 8 );
    setAnswer( octNum );
    setQuestion( "Use pencil and paper to solve the following problem:\n\n" +
      "Convert the binary number " + binNum + " to octal." );
  }

  public String hint()
  {
    return "To convert a binary number to an octal number look at the number 3 bits " +
           "at a time starting at the rightmost bit. Each grouping of 3 bits will have " +
           "column weightings of 4, 2, and 1. For example, the binary number 1010110 could " +
           "be grouped as 1 010 110 and would then be the octal number 126. The 1 gives us a 1, " +
           "the 010 gives us 2, and the 110 gives us 6 (a 1 in the 4's column and a 1 in the 2's column).";
  }
}