V22.0101 ......Homework Assignment 1 Draft #2 ...... Fall 2006
Binary Representation of Numbers

Assigned: MON, FEB 5.
First Version Due (by email to etutor): (Marateck) THURS, FEB 8, at 11:59 pm

Rewrite your first draft so that a class called Binary stores the decimal number in the instance variable numVal and the binary string corresponding to numVal will be stored in the instance variable binStr. The value of the decimal number is passed by the driver class Hw1 to the constructor. The constructor has the heading public Binary(int num) and will assign num to numVal. . The class Binary will have the same two methods you have already written for draft #1. They now have the following form:

You can "hard-wire" the example numbers into the main method, or you can read them from the the keyboard using the JOptionPane class described in the text book (page 45) or the Scanner class (p53 in text, or see the instructions for the first draft) . The simplest form to use for assigning input to a string using JOptionPane, let's say number is String number = JOptionPane.showInputDialog("Type your decimal number");. If you have JDK 1.5 (and I urge you to download it), use the Scanner class.