1. LxD Cycle Process

Empathize: Students write steps that are too vague for a computer, like “Prepare for school, Go to school.” They also think code that compiles is code that works. In 37 million student compilations, the mistakes that took longest to fix were semantic, not syntax (Altadmri & Brown, 2015).

Define:

  • POV: CSA students need to put steps in order and tell syntax, logic, and run-time errors apart, because a program can compile and still give the wrong answer.
  • Learning Goal: Students will write an algorithm as ordered steps, explain how Java code is compiled and run, and name the three types of errors.

Ideate:

  • HMW Question: How might we make “it compiles” and “it works” feel like two separate checks?
  • HMW Question: How might we use an everyday routine to show why step order matters before students see code?
  • Activity: Put the steps of closing a store in order, read a login algorithm next to its Java code, then write and test your own.

Prototype & Test: Lesson authors: add what happened in your trial run and what you changed.


2. Lesson Plan

Learning Objective: Write an everyday algorithm as ordered steps, explain how code is compiled and run, and identify syntax, logic, and run-time errors.

Success Criteria: You can order steps, fix an algorithm with steps out of order, turn an algorithm into code, and name the error type in a broken program.

Tech Talk (5 minutes)

An algorithm is a list of steps in order. Each step runs one at a time, so order and detail decide whether it works.

Java code is compiled before it runs. The compiler catches broken rules, but it cannot catch a wrong answer, so test with data where you know the result.

Code Runner Challenge

Change the values, predict the output, then run it

View IPYNB Source
int test1 = 80;
int test2 = 90;
int average = test1 + test2 / 2;   // compiles, but prints 125 instead of 85
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

From the College Board

AP CSA Unit 1, Topic 1.1 Introduction to Algorithms, Programming, and Compilers. Quoted from the course and exam description (College Board, 2025, pp. 30-31):

  • 1.1.A.2 “Sequencing defines an order for when steps in a process are completed. Steps in a process are completed one at a time.”
  • 1.1.B.2 “A compiler checks code for some errors. Errors detectable by the compiler need to be fixed before the program can be run.”
  • 1.1.C.2 “A logic error is a mistake in the algorithm or program that causes it to behave incorrectly or unexpectedly. These errors are detected by testing the program with specific data to see if it produces the expected outcome.”

3. Reference Guide

Steps in Order

An algorithm is a step-by-step process for a task, like a recipe.

Making a sandwich

  1. Get two slices of bread
  2. Spread peanut butter on one slice
  3. Spread jelly on the other slice
  4. Put the slices together
  5. Cut in half

Notice how each step is clear and in a specific order. That’s an algorithm!

Types of Errors

Error When you find it Example
Syntax The compiler stops you, so the program cannot run yet. System.out.println("Hi") with no semicolon
Logic It runs, but testing shows a wrong answer. test1 + test2 / 2 divides before adding
Run-time (exception) It compiles, then stops while running. 12 / 0 throws an ArithmeticException

Login Algorithm

Code Runner Challenge

Run the three tests, then add a test for a user that does not exist

View IPYNB Source
1. Get username from user
2. Get password from user
3. Check if username exists in database
4. If username doesn't exist → show error message
5. If username exists → compare password
6. If password matches → grant access
7. If password doesn't match → show error message
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

4. Code Examples

A. Simple: Storing Information

Code Runner Challenge

Fill in the steps, then run it until all five tests print the right letter

View IPYNB Source
// CODE_RUNNER: Change the values, predict the output, then run it
public class StoreUserInfo {
    public static void main(String[] args) {
        // Algorithm: Store user information
        int age = 16;
        String name = "Alice";
        boolean isStudent = true;

        System.out.println("Name: " + name);
        System.out.println("Age: " + age);
        System.out.println("Is a student: " + isStudent);

        // Try changing the values and run again!
        // age = 17;
        // name = "Bob";
    }
}

StoreUserInfo.main(null);
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

B. Complex: The Login Algorithm in Java

The steps above, written as code.

// CODE_RUNNER: Run the three tests, then add a test for a user that does not exist
import java.util.HashMap;
import java.util.Map;

public class LoginSystem {
    // Simple user database
    private static Map<String, String> userDatabase = new HashMap<>();

    static {
        userDatabase.put("alice", "password123");
        userDatabase.put("bob", "securepass");
        userDatabase.put("charlie", "mypass456");
    }

    // Login algorithm
    public static boolean login(String username, String password) {
        // Step 3: Check if username exists
        if (!userDatabase.containsKey(username)) {
            // Step 4: Handle user not found
            System.out.println("❌ Error: Username not found");
            return false;
        }

        // Step 5-7: Compare password
        if (userDatabase.get(username).equals(password)) {
            System.out.println("✅ Login successful!");
            return true;
        } else {
            System.out.println("❌ Error: Incorrect password");
            return false;
        }
    }

    public static void main(String[] args) {
        System.out.println("Test 1: Correct login");
        login("alice", "password123");

        System.out.println("\nTest 2: Wrong password");
        login("alice", "wrongpass");

        System.out.println("\nTest 3: User doesn't exist");
        login("david", "anypass");
    }
}
LoginSystem.main(null);

5. Hacks & Practice Tasks

Prepare your submission IPYNB

  1. Create a new notebook in your portfolio homework area: _notebooks/homework.
  2. Add one raw cell at the top with the frontmatter:
---
layout: post
codemirror: true
title: Introduction to Algorithms, Programming, and Compilers HW
categories: [Java]
lesson_language: Java
lesson_topic: Algorithms HW
lesson_part: interactive
lesson_type: lesson
permalink: /csa/unit_01/1_1-hw
author: yourGithubID
---
  1. Add code cells for the Popcorn Hack and the Homework Hack. Make sure every cell runs with visible output.
  2. Submit the link to your published page at the bottom of this page, and paste this in the description box:
Lesson: CSA 1.1 Algorithms, Programming, and Compilers
MCQ 1.1: <paste the copied result line, such as 5/6 | answers: D,A,C,B>
Popcorn: Store Closing solved, screenshot in the notebook
Part A: <activity chosen>, <number> steps
Part B: corrected email order = <your order>
Part C: all five tests print A, B, C, D, F (yes/no)

Submission Safety Rules (Read First)

  • Label each part A, B, and C.
  • Run Part C and leave the output showing.
  • Keep the five test lines in Part C.
  • Include your MCQ score.
  • Use ## headings or smaller.

Popcorn Hack (In-Class)

2-minute challenge: put the 10 steps in order, click Check Answer until you see Perfect!, then screenshot it. Think about what has to happen before each step.

Store Closing Algorithm Challenge

Drag and drop the steps into the correct order

How to Play:

  1. Drag steps from the left column to the position slots on the right
  2. Arrange them in the correct logical order for closing a store
  3. Click "Check Answer" to see if you got it right
  4. Use "Clear All" to start over or "Reset & Shuffle" for a new challenge

Available Steps

Your Order

MCQ Check

4 questions, one at a time. Answer, check, then go to the next one. At the end, copy the score line into your submission notes.

Homework Hack

Task: Do all three parts in your submission notebook.

Part A. Write an algorithm of at least 8 specific steps, in order, for one of these: getting ready for a basketball game, making a pizza from scratch, or setting up a new phone.

Part B. These steps are out of order. Rewrite them correctly.

Algorithm: Send an Email
1. Click "Send"
2. Open email application
3. Type the message
4. Log into your account
5. Enter recipient's email address
6. Write subject line

Part C. Fill in the skeleton below until all five tests print the right letter. The rule: 90 and up is an A, 80 a B, 70 a C, 60 a D, anything lower an F.

# CODE_RUNNER: Fill in the steps, then run it until all five tests print the right letter
def calculate_grade(score1, score2, score3):
    """
    Calculate letter grade from three test scores
    
    Args:
        score1, score2, score3: Test scores (integers)
    
    Returns:
        grade: Letter grade (string)
    """
    # TODO: Your code here!
    # Step 1: Add the three scores together
    
    # Step 2: Calculate the average
    
    # Step 3: Determine the letter grade using if-elif-else
    
    # Step 4: Return the grade
    
    pass  # Remove this when you add your code

# Test your function!
print("Test 1:", calculate_grade(95, 92, 88))  # Should be 'A'
print("Test 2:", calculate_grade(85, 80, 82))  # Should be 'B'
print("Test 3:", calculate_grade(75, 70, 72))  # Should be 'C'
print("Test 4:", calculate_grade(65, 60, 62))  # Should be 'D'
print("Test 5:", calculate_grade(55, 50, 52))  # Should be 'F'

6. Grading Plan (1 Point Total)

Part Points What earns the points
Popcorn 0.2 Screenshot shows the Perfect! You got it right! message.
MCQ 0.2 5 or 6 correct. 0.15 for 3 or 4, 0.1 if every question was answered.
Homework Part A 0.2 Names the activity, 8 or more specific steps, in order.
Homework Part B 0.15 App opened and logged into first, Send last.
Homework Part C 0.25 The five tests print A, B, C, D, F.
Total 1.0  

Quick Validation Checklist

  • Popcorn screenshot with the success message.
  • MCQ score in the notes.
  • Part A has 8 or more numbered steps.
  • Part B keeps all six steps, reordered.
  • Part C output shows A, B, C, D, F.

7. Lesson Revisions & Feedback Evidence

Feedback Received: Lesson authors: what your peers said in the practice run.

Revision Made: Lesson authors: what you changed because of it.


References

Altadmri, A., & Brown, N. C. C. (2015). 37 million compilations: Investigating novice programming mistakes in large-scale student data. In Proceedings of the 46th ACM Technical Symposium on Computer Science Education (pp. 522–527). Association for Computing Machinery. https://doi.org/10.1145/2676723.2677258

College Board. (2025). AP Computer Science A course and exam description [Effective fall 2025]. https://apcentral.collegeboard.org/media/pdf/ap-computer-science-a-course-and-exam-description-effective-fall-2025.pdf

Submit Assignment

Click to upload or drag and drop
PDF, ZIP, images, documents, or Jupyter notebooks (.ipynb) (Max 10MB per file)

Need to update a submission later? Open the submissions dashboard.