Java • Boolean Logic • Console Program
Operators: && • || • !
Includes: Spec • Pseudocode • Rubric • Turn-in List

Boolean Logic Analyzer (Decision Helper)

Build a Java console program that demonstrates boolean variables, boolean expressions, and Boolean logic (AND/OR/NOT), including a compound condition and a De Morgan's Law equivalence check.

Spec Sheet (Student-Facing)

Project Title

Boolean Logic Analyzer (Decision Helper)

Goal

Create a Java console program that demonstrates Boolean logic using boolean variables, boolean expressions, and logical operators (&&, ||, !) with at least one compound condition and at least one De Morgan’s Law equivalent check.

Program Requirements (must-have)

  • Use Scanner to collect user input (at least 4 yes/no or numeric inputs).
  • Store user input in variables and create at least 6 boolean expressions.
  • Use all of these operators at least once:
    • AND &&
    • OR ||
    • NOT !
  • Include at least 3 if / else if / else decision blocks.
  • Print a clear summary showing:
    • The user’s inputs
    • The boolean expression results
    • A final decision/result
  • Include a section that demonstrates De Morgan’s Law by showing two logically equivalent expressions and printing whether they match.
Suggested Theme: “Should I allow this action?” (access control / safety check / eligibility check)
Example: “Can a student enter the lab?” based on badge, teacher present, time, etc.

Files to Turn In (Google Classroom)

Turn in these 2 files (required). Make sure file names match exactly.

Required

  • 1) P1_BooleanLogic_lastname.java — your Java program
  • 2) P1_BooleanLogic_lastname.txt (or .pdf) — a single document that includes:
    • Spec Sheet (you may paste from this page)
    • Your pseudocode (update if you changed design)
    • 3 test cases (inputs + expected outcome + actual outcome)
Optional (extra credit if allowed):
P1_BooleanLogic_lastname_TestCases.png — screenshot(s) of console runs

Quick Naming Notes

Use your last name One .java file One reflection/test doc

Pseudocode

1. Start program
2. Create Scanner
3. Ask user for inputs:
   - Has ID badge? (Y/N)
   - Is teacher present? (Y/N)
   - Is it within allowed hours? (Y/N)
   - Is student on approved list? (Y/N)
   - Number of behavior incidents (integer)
4. Convert inputs into booleans
5. Build boolean expressions:
   - goodBehavior = incidents <= 1
   - verifiedIdentity = hasBadge OR teacherPresent
   - approvedOrEscorted = onApprovedList OR teacherPresent
   - canEnter = verifiedIdentity AND allowedHours AND goodBehavior AND approvedOrEscorted
   - needsEscort = (NOT hasBadge) AND teacherPresent AND allowedHours AND goodBehavior
   - blocked = NOT canEnter
6. De Morgan demo:
   - exprA = NOT (hasBadge OR teacherPresent)
   - exprB = (NOT hasBadge) AND (NOT teacherPresent)
   - print both + print whether exprA == exprB
7. Use if/else if/else to print final decision (enter / enter with escort / deny)
8. Print a summary of all expression results
9. End program

Rubric (100 points)

Category Criteria Points
A. Program Requirements Uses Scanner and collects at least 4 inputs (10)
Creates at least 6 boolean expressions (10)
Uses &&, ||, ! correctly (10)
Uses at least 3 if/else if/else blocks (10)
40
B. Boolean Logic Correctness Compound condition(s) are logically correct and match intent (10)
Output matches logic for multiple scenarios (10)
Includes a correct “blocked/denied” condition using NOT (5)
25
C. De Morgan’s Law Correct equivalent expressions (10)
Prints and compares results clearly (5)
15
D. Code Quality Detailed comments explain what and why (10)
Good variable names and readable formatting (5)
Clear, user-friendly prompts and output (5)
20
Total 100

Final Java Program

Copy/paste into Eclipse (or your Java IDE) and rename the file to match the required turn-in name.

import java.util.Scanner;

/**
 * P1_BooleanLogic_lastname.java
 *
 * Boolean Logic Analyzer (Decision Helper)
 *
 * This program demonstrates:
 * - boolean variables
 * - boolean expressions
 * - && (AND), || (OR), ! (NOT)
 * - compound conditions
 * - De Morgan's Law equivalence
 *
 * Scenario:
 * Decide whether a student can enter a lab based on:
 * - ID badge
 * - teacher presence
 * - allowed hours
 * - behavior incidents
 * - approved list
 */
public class P1_BooleanLogic_lastname {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        System.out.println("=== Boolean Logic Analyzer: Lab Entry Decision ===");
        System.out.println("Answer with Y or N when prompted.\n");

        // ----------------------------
        // 1) INPUT SECTION
        // ----------------------------

        // Collect yes/no inputs as strings, then convert to booleans.
        System.out.print("Does the student have an ID badge? (Y/N): ");
        String badgeAnswer = input.nextLine().trim();

        System.out.print("Is a teacher present? (Y/N): ");
        String teacherAnswer = input.nextLine().trim();

        System.out.print("Is it within allowed hours? (Y/N): ");
        String hoursAnswer = input.nextLine().trim();

// Missing code *******************************************

        // Convert Y/N to boolean.
        // equalsIgnoreCase("Y") returns true for "Y" or "y".
        boolean hasBadge = badgeAnswer.equalsIgnoreCase("Y");
        boolean teacherPresent = teacherAnswer.equalsIgnoreCase("Y");
        boolean allowedHours = hoursAnswer.equalsIgnoreCase("Y");
        boolean onApprovedList = approvedAnswer.equalsIgnoreCase("Y");

        // ----------------------------
        // 2) BOOLEAN EXPRESSIONS SECTION
        // ----------------------------
        // The goal here is to create meaningful boolean expressions
        // that represent policy rules.

        // Expression 1: Behavior is acceptable if incidents are 0 or 1
        boolean goodBehavior = (incidents <= 1);

        // Expression 2: Basic supervision rule (teacher present AND allowed time)
        boolean supervisedAndOnTime = (teacherPresent && allowedHours);

        // Expression 3: Badge rule (has badge AND allowed time)
        boolean badgeAndOnTime = (hasBadge && allowedHours);

        // Expression 4: Basic identity rule (has badge OR teacher present)
        // Why OR? Because if a teacher is present, they can verify the student.
        boolean verifiedIdentity = (hasBadge || teacherPresent);

        // Expression 5: Approved rule (must be approved OR teacher present overrides for supervision)
        // This simulates a policy where a teacher can escort a non-approved student.
        boolean approvedOrEscorted = (onApprovedList || teacherPresent);

        // Expression 6: Final entry rule (compound condition)
        // Student can enter if:
        // - identity is verified
        // - it is allowed hours
        // - behavior is good
        // - student is approved OR teacher is present (escort override)
        boolean canEnter = (verifiedIdentity && allowedHours && goodBehavior && approvedOrEscorted);

        // Expression 7: Needs escort (no badge, but teacher present, during allowed hours, and behavior good)
        boolean needsEscort = (!hasBadge && teacherPresent && allowedHours && goodBehavior);

        // Expression 8: Blocked (NOT canEnter)
        boolean blocked = !canEnter;

        // ----------------------------
        // 3) DE MORGAN'S LAW DEMO
        // ----------------------------
        // De Morgan's Law examples:
        // NOT (A OR B)  == (NOT A) AND (NOT B)
        boolean deMorganLeft = !(hasBadge || teacherPresent);
        boolean deMorganRight = (!hasBadge && !teacherPresent);
        boolean deMorganMatches = (deMorganLeft == deMorganRight);

        // ----------------------------
        // 4) OUTPUT / DECISION SECTION (if/else if/else)
        // ----------------------------
        System.out.println("\n=== Decision Result ===");

        // Decision block 1:
        if (canEnter && !needsEscort) {
            System.out.println("ACCESS GRANTED: Student may enter the lab normally.");
        }
        // Decision block 2:
        else if (canEnter && needsEscort) {
            System.out.println("ACCESS GRANTED WITH ESCORT: Teacher must accompany the student.");
        }
        // Decision block 3:
        else {
            System.out.println("ACCESS DENIED: Student may NOT enter the lab.");
        }

        // ----------------------------
        // 5) SUMMARY SECTION
        // ----------------------------
        System.out.println("\n=== Input Summary ===");
        System.out.println("Has Badge: " + hasBadge);
        System.out.println("Teacher Present: " + teacherPresent);
        System.out.println("Allowed Hours: " + allowedHours);
        System.out.println("On Approved List: " + onApprovedList);
        System.out.println("Behavior Incidents: " + incidents);

        System.out.println("\n=== Boolean Expression Results ===");
        System.out.println("goodBehavior (incidents <= 1): " + goodBehavior);
        System.out.println("supervisedAndOnTime (teacherPresent && allowedHours): " + supervisedAndOnTime);
        System.out.println("badgeAndOnTime (hasBadge && allowedHours): " + badgeAndOnTime);
        System.out.println("verifiedIdentity (hasBadge || teacherPresent): " + verifiedIdentity);
        System.out.println("approvedOrEscorted (onApprovedList || teacherPresent): " + approvedOrEscorted);
        System.out.println("canEnter (verifiedIdentity && allowedHours && goodBehavior && approvedOrEscorted): " + canEnter);
        System.out.println("needsEscort (!hasBadge && teacherPresent && allowedHours && goodBehavior): " + needsEscort);
        System.out.println("blocked (!canEnter): " + blocked);

        System.out.println("\n=== De Morgan's Law Check ===");
        System.out.println("Left:  !(hasBadge || teacherPresent) = " + deMorganLeft);
        System.out.println("Right: (!hasBadge && !teacherPresent) = " + deMorganRight);
        System.out.println("Do they match? " + deMorganMatches);

        input.close();
        System.out.println("\nProgram complete.");
    }
}
Reminder: Replace lastname in the class name and filename with your actual last name.