Re-write Assignment #1 using Object Oriented Programming concepts (chapter 7)
Binary Representation of Numbers using OOP Due Tuesday 10/23/07 (by 11:59 pm)
Rewrite your assignment #1 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.
You should check to make sure that the decimal value is between 0 and 255.
If it is not, it should print an informative error message (using System.out.println) and store the number 0 instead.
The value of the decimal number is passed by the Test class (client class / driver class) Assignment # 1 to the constructor.
The client class or test class will have the following statements in the main method:
Binary bin = new Binary(num);
boolean valid= bin.checkBin();
Note that getBin() and checkBin() have no parameters. The necessary information is passed through 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 Assignment #1.
They now have the following form:
public void getBin(): This produces the string consisting of the binary equivalent of numVal prints it and assigns it to the instance variable binStr.
public boolean checkBin(). This take the binary string in binStr and checks to see if it correctly represents the number in numVal. If it does, it returns true to the client/test/driverclass, assignment #1, else it returns false.
Provide the UML diagram for this assignment.
(Please note that you can draw the UML diagaram by hand or use any program to produce the diagram such as Microsoft Word)
Create a third method in the implementation class (the blue-print class or the class with constructors) to convert the decimal number enterd by the user to a hexadecimal number and return it to the the client class.