[SOLVED] True and False

20.00 $

Categories: ,
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon 10672661.zip (1.3 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
đź”’ Securely Powered by:
Secure Checkout
5/5 - (1 vote)

Consider the interface below, implement two classes True and False where each of them implements the Bool class. The function logicalAnd is similar to the primitive && with no short circuiting, and the function ifThenElse accepts two CodeBlock objects and the first argument would be executed if the Bool object is True, second argument would be executed instead if the Bool object is False.

interface Bool {

Bool logicalAnd();

void ifThenElse(CodeBlock b1, CodeBlock b2);

}

For example, the code snippet below would print the string “bye world!”.

Bool b1 = new True();

Bool b2 = new False();

Bool b3 = b1.logicalAnd(b2);

b3.ifThenElse(new CodeBlock() {

public void execute() {

System.out.println(“hello world!”);

}

},

new CodeBlock() {

public void execute() {

System.out.println(“bye world!”);

}

});

The implementation must not contain any keywords instanceof, if, else, and it also must not use primitive types such as int, boolean and built-in classes such as String.

  • 10672661.zip