← Student pageCard Sort Challenge1 /
00:00.00
AP Computer Science A, Semester 2, Day 1

Card Sort Challenge

You already know how Java uses classes, objects, attributes, methods, conditionals, and Boolean expressions. Today we will review those ideas physically, then preview where collections and sorting will take us next.

Your team

Work in groups of about four.

  1. Introduce yourself if needed.
  2. Place one shuffled deck in the center.
  3. Do not begin sorting until the presentation says GO.
  4. Your goal is speed and correctness.
The four suits

Know your data.

HeartsHearts
DiamondsDiamonds
ClubsClubs
SpadesSpades
The target

Sort the entire deck.

A 2 3 4 5 6 7 8 9 10 J Q K

How to finish

Your timer stops only when...

  1. All 52 cards are sorted correctly.
  2. The four suits are each together and ordered A through K.
  3. The cards are combined into one deck.
  4. The deck is turned face down.
  5. No one is touching the deck.
  6. Every teammate has both hands in the air.
Round 1

No planning period.

Make sure the deck is shuffled. Put it face down in the center. When this slide changes to GO, begin immediately.

Hands off. Get ready.

Round 1

GO!

Sort the deck as quickly and accurately as you can.

When finished: deck face down, hands off, both hands up.

Accuracy check

Fast and wrong is still wrong.

Keep your deck face down until your teacher checks it. If a card is out of order, the group is not finished yet.

Correctness comes before bragging rights.

Round 1 debrief

What happened?

Where did people collide or reach for the same cards?

Was anyone waiting without a clear job?

What part of the task took the most time?

What would your team change next time?

Round 2 planning

You get 60 seconds to design.

Do not touch the cards. Decide your strategy before execution.

Roles

Who will handle which cards?

Layout

Where will each suit or partial result go?

Combine

How will separate piles become one deck?

Verify

Who checks that the result is correct?

Round 2 setup

Prepare to run your new algorithm.

  1. Shuffle the deck again.
  2. Place it face down in the center.
  3. Move your hands away from the cards.
  4. Do not change the plan once the round begins unless your team discovers a problem.

Ready?

Round 2

GO!

Execute the plan.

Remember: sorted deck, face down, nobody touching, both hands up.

Compare your evidence

Round 1 vs. Round 2

Time

Did your group get faster?

Correctness

Did you make fewer mistakes?

Coordination

Did everyone have a clearer role?

Algorithm

What specific step changed?

Review from Semester 1

A playing card is an object.

Class

Card is the blueprint.

Object

The Queen of Hearts is one specific Card object.

Attributes

suit and rank describe its state.

Methods

getSuit() and getRank() expose useful behavior.

Review: class design

What would this class need?

public class Card { private String suit; private int rank; public Card(String s, int r) { suit = s; rank = r; } public String getSuit() { return suit; } public int getRank() { return rank; } }

Nothing here is new. This is a review of objects, constructors, attributes, and accessor methods.

Preview, not prior knowledge

But what is the whole deck?

A deck is many Card objects kept together in an order.

How could Java store 52 related objects?

That question leads us into our next major idea: collections.

New idea preview

Arrays hold many related values.

Card[] deck = new Card[52];

You have not learned arrays yet. For today, just notice the idea: instead of 52 separate variable names, one structure can hold many Card objects.

Later extension

ArrayList is another collection.

ArrayList<Card> deck = new ArrayList<Card>();

ArrayList will also be new. It can grow and shrink, and it gives us methods for adding, removing, and retrieving objects.

Today, your physical deck is simply a preview of why collections are useful.

Methods connect actions to code

What did your team actually do?

getRank()
inspect a card

getSuit()
identify its group

compare(...)
decide which comes first

swap(...)
change positions

Some of these methods are familiar. Others preview methods we could design later.

Your strategy was an algorithm

Same problem. Different procedures.

An algorithm is a precise sequence of steps for solving a problem. Every team attempted to transform the same shuffled input into the same kind of sorted output.

Which steps made your solution better?

Preview: sorting algorithms

Your team may have discovered these ideas naturally.

Selection-like

Find the next smallest card, place it, repeat.

Insertion-like

Maintain an ordered pile and insert each new card where it belongs.

Divide and combine

Split by suit, sort smaller groups, then recombine.

Hybrid

Combine strategies when one approach is not enough.

You do not need to know the Java implementations yet. We will return to these ideas later.

Think like a programmer

What made Round 2 better?

Exit reflection

Connect the physical activity to Java.

  1. Describe your Round 2 strategy as a sequence of steps.
  2. How does one playing card connect to a Java object?
  3. What are two attributes a Card object should have?
  4. What methods could a Card or future Deck class need?
  5. Why might a collection be useful for representing a full deck?
Semester 2 begins here

Objects work together.

You already know how to model one object. This semester we will increasingly work with many objects, collections of objects, and algorithms that process them.

Plan → Execute → Test → Improve