Design and implement an application that simulates binary integers using boolean arrays. Repeatedly (but at least once) execute the following steps:
  1. Declare a boolean array (but don't initialize yet), a long variable (initialize to 0), and a String variable (initialize to "")
  2. Ask the user what type they want (byte, short, int)
  3. Assign an appropriate size boolean array to the declared array variable (8 for byte, 16 for short, etc.)
  4. Randomly initialize each variable in the array to true or false (Hint: The Random class in the java.util package has an instance method that can generate random true and false values.)
  5. Process the boolean array as if it were a binary number, which you can accomplish via the following steps:
  6. Print both the binary representation and the integer value.
  7. Prompt the user to continue or quit

Code:


// Import any classes from java.util, as needed

public class BinaryWithBooleans {


    public static void main(String[] args) {















    }

    // This may be easier than Math.pow(...) because
    // you won't have to do any casting.
    private static long power(long base, long exponent){
        if (exponent == 0)
            return 1;
        else if (exponent == 1)
            return base;
        else{
            long median = (exponent % 2 == 0) ? exponent / 2 : (int) Math.ceil(exponent / 2.0);
            return power(base, median) * power(base, exponent - median);
        }
    }

}

Program output example:

What type of integer do you want?
1 for byte
2 for short
3 for int

Make your choice: 1
You chose...byte

01001010 is 74

Continue (true or false): true

What type of integer do you want?
1 for byte
2 for short
3 for int

Make your choice: 2
You chose...short

1101101101000111 is -9401

Continue (true or false): true

What type of integer do you want?
1 for byte
2 for short
3 for int

Make your choice: 3
You chose...int

10011100001101001001000101011011 is -1674276517

Continue (true or false): false
        
Question: How did the process of editing this program go for you? What were your main challenges and how did you overcome them? What did you learn that may be of use as you move along in this class?