CSCI-UA.0101 ......Homework Assignment 1 Draft #2 ...... Fall 2012
Base 8 Representation of Numbers

Assigned: THU, SEPT 27.
First and final version Due (by email to etutor): (Marateck) SUN OCT 7, 11:59pm

Rewrite your original program (we called it draft 1) so that a class called Base8 stores the decimal number in the instance variable numVal and the base 8 string corresponding to numVal will be stored in the instance variable octalStr. The value of the decimal number is passed by the class Hw1a (it's called the driver class and contains the main method) to the constructor in Base8.

The main method will read the decimal number from the keyboard and then include the following statements:

Base8 obj = new Base8(num);	
boolean valid= obj.checkOctal();

Note that getOctal() and checkOctal() have no parameters. The necessary information is passed through the constructor to the instance variable numVal in the instantiated class Base8.

The constructor has the heading public Base8(int num) and will assign num to the instance variable numVal. The class Base8 will have the same two methods you have already written for draft #1 except now they will convert to base 8 and from base 8, and will have the following form:

The input should be read using the Scanner class only -- no command line this time and don't check for valid input using a loop.

You may write getOctal() so that it returns the value of octalStr, i.e., the signature would be public String getOctal(). So that the statements in the if block in the main method could include:

Base8 bin = new Base8(num);
System.out.println( bin.getOctal() );
boolean valid= bin.checkOctal();