Week 8 Day 1 - Arrays of Objects
Find code from class here.
The purpose of today’s class is to get more experience with constructing and working with classes.
Questions from the Reading
Why did they implement 0 as “null”?
Why do we need to write a toString() method? What happens if we do not?
What is “that.[name]”? What is “that” referring to?
What is “final”? What is “static”?
How does binary search work?
Lecture/Live-Code
For today’s class I’m going to implement the Card
class from the reading and discuss questions as they come up. If you miss class and have questions about the implementation of these structures, make sure to see me.
In-Class Exercise
In your groups, complete exercise 12.3 from your book. You can download or copy our implementation of the Card()
class from here.
In Poker a “flush” is a hand that contains five or more cards of the same suit. For these purposes, hand can contain any number of cards.
- Write a method called
suitHist()
that takes an array ofCard
s as a parameter and returns a histogram of the suits in the hand. Your solution should traverse the array only once, as in Section 7.7. - Write a method called
hasFlush()
that takes an array ofCard
s as a parameter and returnstrue
if the hand contains a flush (andfalse
otherwise). - A “royal flush” includes the Ace, King, Queen, Jack, and 10 (all in the same suit). Write a method called
hasRoyal()
that determines whether an array ofCard
s contains a royal flush.