CSCI-1320 Homework 06: Boolean Expressions

Instructor: Todd Dole

Purpose Statement

This assignment provides opportunity for you to become comfortable evaluating and constructing boolean expressions. The goal is for you to become comfortable with the syntax and semantics of boolean expressions. If after you finish this assignment you feel that you aren't totally comfortable with boolean expressions yet, then you'll want to invest some additional time to make sure you understand them.

Instructions

Prelab:

                boolean havingFun, amTired;
                int i, j, x, y;
                double a, b;

                havingFun = true;
                amTired = false;
                i = 0;
                j = 10;
                x = 5;
                y = -3;
                a = 5.5;
                b = 3.2;
            

Given these variable declarations and initializations, do the following:

  1. By hand, calculate the value of each of the following boolean expressions. (Write your answers down).
  2. Construct a program to calculate each of the following boolean expressions. You can have it print either "True" or "False" for each expression. The program should use a Class named BooleanChallenge (and save it as BooleanChallenge.java)
  3. Compare your answers with the computer's answers. Reconcile any differences.
  4. In the comment header at the top of your program, identify the expressions that you calculated incorrectly on your first attempt. If you got them all correct on your first attempt then say so.
  5. Once you are done with the original twenty, add a new boolean expression to your program of your own design. We'll share these with the class and see if we can stump each other.
  6. Submit your complete assignment in Canvas.

Boolean Expressions to Evaluate:

        1.   amTired
        2.   i < 0
        3.   j < i || j < 100
        4.   i < j < 100
        5.   !amTired || havingFun && i > 10
        6.   !havingFun || j > 0 || amTired
        7.   !(i > 0 && !havingFun) || amTired
        8.   x > y && a < b
        9.   x + y > 0 && a - b < 2.5
        10.  i == j || a != b && havingFun
        11.  (i + j) % 2 == 0 && amTired
        12.  i == 0 || y < x && a > b
        13.  !(j == 10) || havingFun && !amTired
        14.  x > 0 && i >= 0 && j <= 20
        15.  (x - y) < 10 || (b - a) > 0
        16.  x * y > -20 && j / 2 == 5
        17.  x != 5 || j < 20 && !havingFun
        18.  i + x >= j && b * 2 <= a
        19.  !(x == 5 || y != -3) && amTired
        20.  i == j && a == b || havingFun && amTired