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.
A 2 3 4 5 6 7 8 9 10 J Q K
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.
Sort the deck as quickly and accurately as you can.
When finished: deck face down, hands off, both hands up.
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.
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?
Do not touch the cards. Decide your strategy before execution.
Who will handle which cards?
Where will each suit or partial result go?
How will separate piles become one deck?
Who checks that the result is correct?
Ready?
Execute the plan.
Remember: sorted deck, face down, nobody touching, both hands up.
Did your group get faster?
Did you make fewer mistakes?
Did everyone have a clearer role?
What specific step changed?
Card is the blueprint.
The Queen of Hearts is one specific Card object.
suit and rank describe its state.
getSuit() and getRank() expose useful behavior.
Nothing here is new. This is a review of objects, constructors, attributes, and accessor methods.
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.
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.
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.
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.
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?
Find the next smallest card, place it, repeat.
Maintain an ordered pile and insert each new card where it belongs.
Split by suit, sort smaller groups, then recombine.
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.
Card object should have?Card or future Deck class need?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