Problem Statement
You have been given a code snippet formatted as follows:
int x = a if (x OP1 b LOG x OP2 c) print "msg1" else print "msg2"Where a, b, and c are positive integers, OP1 and OP2 are either > or <, LOG is either AND or OR, and msg1 and msg2 are strings of letters and spaces. You must either return either msg1 or msg2 depending on which is printed. Remember that AND requires both conditions to be true whereas OR requires at least one. Each line above will be a separate element of snippet (line 0 will be element 0, etc.).
Definition
- Class:
- IfCodeCheck
- Method:
- getOutput
- Parameters:
- String[]
- Returns:
- String
- Method signature:
- String getOutput(String[] snippet)
- (be sure your method is public)
Notes
- Don't be alarmed by the presence of \" in the input. It will show up as a " when your code receives it.
Constraints
- snippet will contain exactly 5 elements.
- Element 0 of snippet will have the format (quotes for clarity): "int x = a". Here a is positive integer between 1 and 100 inclusive with no leading zeros.
- Element 1 of snippet will have the format (quotes for clarity): "if (x OP1 b LOG x OP2 c)". Here OP1 and OP2 are either (quotes for clarity) "<" or ">". LOG is either (quotes for clarity) "AND" or "OR". b and c are positive integers between 1 and 100 inclusive with no leading zeros.
- Elements 2 and 4 of snippet will have the format (single quotes for clarity): 'print "msg"', where msg contains at least 1 character. Each character in msg will be a letter ('a'-'z' or 'A'-'Z') or a space (' ').
- Elements 2 and 4 of snippet contain between 9 and 50 characters inclusive.
- Element 3 of snippet will be (quotes for clarity): "else".
- No element of snippet will contain leading or trailing whitespace.
Examples
{"int x = 10", "if (x < 5 OR x > 9)", "print \"Condition Was True\"", "else", "print \"Condition Was False\"" }Returns: "Condition Was True"
Here x > 9 and the logical operation is OR so the condition holds.{"int x = 10", "if (x < 5 AND x > 9)", "print \"Condition Was True\"", "else", "print \"Condition Was False\"" }Returns: "Condition Was False"
This is the same as the previous example, but the logical operation is now AND. Since x is not less than 5 the condition fails.{"int x = 55", "if (x > 50 AND x < 90)", "print \"Condition Was True\"", "else", "print \"Condition Was False\"" }Returns: "Condition Was True"
Here we test for x between 50 and 90 exclusive. 55 does satisify this condition.{"int x = 100", "if (x > 1 AND x > 1)", "print \" \"", "else", "print \"AaAaAaA\"" }Returns: " "
The returned message is a single space.{"int x = 100", "if (x > 100 OR x < 100)", "print \" \"", "else", "print \"A a A A a A a A a A a A A A\"" }Returns: "A a A A a A a A a A a A A A"
100 is neither greater than nor less than 100.