Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // represents the and/or function taking in two TrueFalses
- // @author Chris Tsuei
- public class BooleanOperation extends TrueFalse{
- /* Operation is the operation to be done
- * first and second are the TrueFalses to be done and evaluated
- */
- private Operator operation;
- private TrueFalse first;
- private TrueFalse second;
- /* The constructor for BooleanOperation
- * @param operator the operation to be done
- * @param one the first TrueFalse to be done
- * @param two the second TrueFalse to be done
- */
- public BooleanOperation(Operator operator, TrueFalse one, TrueFalse two) {
- this.operation = operator;
- this.first = one;
- this.second = two;
- }
- //the enum of operations that can be done in this class
- public enum Operator {
- //the two possible TrueFalses, ADD and Or
- Add, Or;}
- /* evaluating the expressions
- * @Override
- * @param state the hashtable containing the variables for the expressions
- * @return the result of the and/or TrueFalse between two TrueFalses
- */
- public boolean value(State state) {
- if(operation.equals("Add")) {
- return first.value(state) && second.value(state);
- }
- else {
- return first.value(state) || second.value(state);
- }
- }
- /* @Override overides the toString() method
- * @return returns the string value of the operation
- */
- public String toString() {
- String c;
- if(operation.equals("Add")) {
- c = "&&";
- }
- else {
- c = "||";
- }
- return first.toString() + " " + c + " " + second.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement