← Student pageObject-Oriented Blueprint1 /
Welcome to AP Computer Science A

From Snap! sprites to Java objects.

Today you will use physical LEGO bricks to discover the ideas behind object-oriented programming before we write Java.

You already know more than you think

Remember the Snap! sprite.

Information

x position, y position, direction, costume, variables

Actions

move, turn, say, custom blocks

Java uses different words for a very similar idea.

The bridge

Sprite → Object

Snap!

move 10 stepsturn 15°

A sprite stores information and responds to blocks.

OBJ

Java

An object stores attributes and responds to methods.

First challenge: setup

Your partner is the computer.

Partner A

Gets one bag of 10–15 LEGO bricks.

Partner B

Gets an identical bag of 10–15 LEGO bricks.

  1. Place a folder or binder between you.
  2. You may not look at each other’s workspace.
  3. Keep the two LEGO sets separate.

Do not start building yet.

Step 1: Build

Partner A builds the “program.”

  1. Partner A builds a small, unique structure.
  2. Use only pieces from your LEGO bag.
  3. Partner B may not look.
  4. Keep the structure intact when you finish.

Simple enough to describe, complex enough to be interesting.

Step 2: Write the algorithm

Explain exactly how to recreate it.

  1. Partner A writes numbered, step-by-step directions.
  2. Use words only. No drawings, photos, pointing, or gestures.
  3. Name pieces carefully: color, size, orientation, and position.
  4. Assume your partner cannot read your mind.

Could a stranger follow your directions without asking a question?

Step 3: Run the program

Partner B executes the algorithm.

  1. Partner B starts with the matching unused LEGO set.
  2. Read and follow the instructions exactly as written.
  3. Partner A may not explain, correct, point, or give hints.
  4. If a direction is unclear, make your best literal interpretation and continue.

Computers do not ask, “Is this what you meant?”

Step 4: Test and debug

Lift the barrier.

  1. Compare the original structure and the replica.
  2. Find the first place they differ.
  3. Locate the instruction that caused the difference.
  4. Rewrite that instruction so it is more precise.

Logic error

The instruction runs, but produces the wrong result.

Compilation-style error

The instruction cannot be carried out as written.

Debrief

What did the LEGO activity teach us?

Algorithm

A precise sequence of steps for solving a problem or completing a task.

Execution

The instructions are followed in order.

Testing

Compare the result with what you expected.

Debugging

Find the cause of a problem and improve the instructions.

A computer does what you tell it to do, not what you want it to do.

Pick up one brick

Class or object?

Did LEGO invent the exact physical piece in your hand, or did it design a mold or blueprint that could make millions of similar pieces?

Class

The blueprint, design, or type of thing.

Object

One actual instance made from that blueprint.

Partner talk

Describe one brick object.

Attributes

What information describes it?

color, length, width, stud count, attached or not...

Methods

What could it do?

snapTo(), disconnect(), rotate(), printDetails()...

Build challenge

Design a Vehicle class.

  1. Work in a group of 2 to 3.
  2. List 3 attributes every vehicle should have.
  3. List 2 methods every vehicle should be able to perform.
  4. Build two different vehicle objects from the same class.

You have 10 minutes.

Your two objects

Same class. Different state.

Both builds belong to the Vehicle class, but their attribute values can be different.

Object 1

Red racecar, 4 wheels, speed = 8

Object 2

Blue truck, 6 wheels, speed = 4

Connect it to objects

Algorithms live inside methods.

Earlier, your written LEGO directions told your partner exactly how to produce a result.

driveForward()

The method name gives the behavior a useful name.

Inside the method

An algorithm gives the precise steps the computer executes.

Method outside. Algorithm inside.

Abstraction

What is this?

“A car.”

You did not describe every stud, edge, connection, and plastic piece. You used one useful high-level idea to hide complexity.

Abstraction means focusing on what matters while hiding unnecessary detail.

From abstraction to Java

A class is a programming blueprint.

public class Vehicle { private String color; private int wheelCount; public void driveForward() { // algorithm goes here } }

You do not need to understand every symbol yet. Notice the ideas you already created with bricks.

Translate the model

You just modeled object-oriented programming.

Class

Vehicle, the blueprint

Objects

Your two physical vehicles

Attributes

color, wheel count, speed

Methods

driveForward(), turn()

The big idea

Abstraction outside. Algorithm inside.

Abstraction

Lets us say Vehicle instead of thinking about every low-level detail.

Algorithm

Defines the precise steps that make a method actually work.

Classes organize complexity. Methods organize behavior.

Exit reflection

Make the bridge explicit.

  1. How is a Snap! sprite similar to a Java object?
  2. What is the difference between a class and an object?
  3. Give one attribute and one method from your Vehicle class.
  4. How did today's activity demonstrate both abstraction and algorithms?
Where we go next

Tomorrow, the bricks become code.

We will begin learning the Java syntax used to create variables, call methods, and build objects.

The syntax is new. The ideas are not.