Quiz1 Cipher

Quiz 1 - The Escape Room Challenge

Duration: 30 minutes
Total Points: 100 points
Open Book: You may reference lab materials and solutions

Scenario

You’re trapped in a digital escape room! To escape, you must solve a series of programming puzzles that unlock the door. Each puzzle builds on the previous one, and you need ALL codes to escape.


The Challenge: Digital Lock Breaker (100 points)

Write a complete Java program called EscapeRoom.java that helps you break through a multi-layer security system:

Puzzle 1: The Name Cipher (15 points)

  • Ask the user for their first and last name
  • Create a “cipher key” by calculating the sum of ALL digits found in both names
  • If no digits exist in the names, use the length of the full name as the cipher key
  • Display: "Cipher key generated: [key]"

Example: Name “John2Smith9” → digits are 2,9 → cipher key = 11

Puzzle 2: The Memory Bank (25 points)

  • Ask the user to enter exactly 6 numbers (these represent memory bank values)
  • Twist: After entering all 6 numbers, randomly pick one and ask the user to enter it again from memory
  • Use (int)(Math.random() * 6) + 1 to pick which position (1-6) to verify
  • If they get it wrong, make them start over with all 6 numbers
  • Calculate the average of all 6 numbers and display it with 2 decimal places

Puzzle 3: The Pattern Lock (30 points)

  • Using the cipher key from Puzzle 1, generate a special pattern:
  • Print numbers from 1 to 20, but with these rules:
    • If a number is divisible by the cipher key: print “BUZZ”
    • If a number contains the cipher key as a digit: print “FIZZ”
    • If both conditions are true: print “FIZZBUZZ”
    • Otherwise: print the number
  • Edge case: If cipher key is 1, only apply the “contains digit” rule

Puzzle 4: The Time Lock (20 points)

  • Convert the average from Puzzle 2 into “time format”
  • Treat the integer part as total seconds
  • Display it as HH:MM:SS format using printf
  • Then use a switch statement to display a message based on the hours:
    • 0 hours: “Midnight escape!”
    • 1-5 hours: “Dawn break!”
    • 6-11 hours: “Morning mission!”
    • 12-17 hours: “Afternoon adventure!”
    • 18-23 hours: “Evening escape!”
    • Default: “Time anomaly detected!”

Final Challenge: The Master Code (10 points)

  • Take the last digit of the cipher key
  • Take the first digit of the integer part of the average
  • Take the number of “BUZZ” words printed in the pattern
  • Multiply all three together
  • If the result is even, display ”🔓 ESCAPE SUCCESSFUL!”
  • If odd, display ”🔒 ACCESS DENIED - Try again!”

Sample Run:

=== DIGITAL ESCAPE ROOM ===
Enter your first name: Alex3
Enter your last name: Code7
Cipher key generated: 10

Enter memory bank value 1: 45
Enter memory bank value 2: 23
Enter memory bank value 3: 67
Enter memory bank value 4: 12
Enter memory bank value 5: 89
Enter memory bank value 6: 34
Verification: Re-enter value 3: 67
✓ Memory verified! Average: 45.00

Pattern Lock Sequence:
1, 2, 3, 4, 5, 6, 7, 8, 9, BUZZ, 11, 12, 13, 14, 15, 16, 17, 18, 19, BUZZ

Time Lock: 00:00:45
Midnight escape!

Master Code Calculation:
Last digit of cipher (0) × First digit of average (4) × BUZZ count (2) = 0
🔒 ACCESS DENIED - Try again!

Grading Criteria:

  • Puzzle 1 - Name Cipher (15 points): Correctly extracts digits from names and calculates cipher key
  • Puzzle 2 - Memory Bank (25 points): Implements random verification, handles retries, calculates average
  • Puzzle 3 - Pattern Lock (30 points): Complex conditional logic with multiple rules and counting
  • Puzzle 4 - Time Lock (20 points): Time conversion and switch statement implementation
  • Final Challenge (10 points): Multi-step calculation and final condition check

Technical Requirements:

  • Use Scanner for all input operations
  • Apply while or do-while loops for retries and validation
  • Implement nested conditionals and complex logic
  • Use Math.random() for randomization
  • Apply printf for formatted output
  • Extract digits from strings using mathematical operations
  • Convert between data types appropriately
  • Close Scanner when done

Strategy Tips:

  • Break down each puzzle - Don’t try to solve everything at once
  • Test incrementally - Get each puzzle working before moving to the next
  • Use the lab examples - Adapt similar patterns from the lab solutions
  • Focus on logic first - Get the algorithm right, then worry about formatting
  • Handle edge cases - What if cipher key is 0? What if no digits in name?

Hidden Complexity:

This challenge requires you to combine concepts in new ways:

  • String processing + mathematical operations (Puzzle 1)
  • Random numbers + input validation + loops (Puzzle 2)
  • Complex conditional logic + counting + digit manipulation (Puzzle 3)
  • Data conversion + switch statements (Puzzle 4)
  • Multi-variable calculations + final decision logic (Final Challenge)

The real challenge isn’t just knowing the syntax - it’s applying multiple concepts together to solve novel problems!

Time Management: 5 min planning → 20 min coding → 5 min testing and debugging

Good luck escaping! 🚪