The purpopse of this assignment is for you to write a program that reads
an int called numValue, converts it to a binary number, converts
it back to a decimal, and finally checks that the conversion was done
correctly. In the main() method check that the value read is less tha
256 and greater than 0. Then do the following:
- Write a method with the heading public static String getBin(int
numValue) that converts the int to binary. Base this method on
program Reverse1 done on Sept 11. But now as opposed to that program,
each digit you obtain must be concatenated with a string to form the binary
number which is returned by the method. Do this by dividing and moding by 2.
- Write a method with the heading public static boolean checkBin(String
binStr, int numValue) that converts the string binStr consisting of
bits (0's and 1's) to the decimal equivalent and checks if it equals the value
of numValue. If it does, the method returns true, else false. Base this
method on program Convert done on Sept 6.
- The first time you write the program, hardwire the input but when you
submit the program, read the number from the the keyboard using
the Scanner class described in the text book (page 27). This part of the
program is worth a maximum value of 3.8.
- To get a maximum value of 4.0, write the program so that it reads the
original decimal number from the command line. See pp358-359.