// Encapsulation of binary numbers import java.util.Scanner; class BinaryNumber { // Store the binary number as an array of boolean static final int NBITS = 8; private boolean [] bits = new boolean [NBITS]; /** Constructor initializes with low bits at end of array */ public BinaryNumber(String s) { // Fill this in } /** Convert to decimal integer value */ public int intValue() { // Fill this in } /** Determine if two BinaryNumbers are equivalent */ public boolean equals(BinaryNumber b2) { // Fill this in } /** Produce String representation of BinaryNumber */ public String toString() { // Fill this in } /** Add one BinaryNumber to another */ // Define this method and code it // Main method to test BinaryNumber public static void main(String[] args) { // Prompt for numbers if not on command line String number1, number2; if (args.length < 1) { Scanner input = new Scanner(System.in); System.out.print("Enter two eight bit binary numbers: "); number1 = input.next(); number2 = input.next(); } else { number1 = args[0]; number2 = args[1]; } BinaryNumber b1 = new BinaryNumber(number1); BinaryNumber b2 = new BinaryNumber(number2); BinaryNumber b3; System.out.println("b1 is " + b1 + " (" + b1.intValue() + ")"); System.out.println("b2 is " + b2 + " (" + b2.intValue() + ")"); System.out.println("b1.equals(b2) is " + b1.equals(b2)); b3 = b1.add(b2); System.out.println("b3=b1.add(b2) is " + b3 + " (" + b3.intValue() + ")"); b3 = b3.add(b1); System.out.println("b3=b3.add(b1) is " + b3 + " (" + b3.intValue() + ")"); b2 = b2.add(b1).add(b1); System.out.println("b2=b2.add(b1).add(b1) is " + b3 + " (" + b2.intValue() + ")"); System.out.println("b2.equals(b3) is " + b2.equals(b3)); } }