4. |
Devise another class, Billfold, which contains slots for two cards, card1 and card2, a method void addCard(Card) and a method String formatCards().
The addCard method checks if card1 is null. If so, it sets card1 to the new card. If not, it checks card2. If both cards are set already, the method has no effect. (In Chapter 13 you will learn how to collect an arbitrary number of items.)
Of course, formatCards invokes the format method on each non-null card and concatenates the resulting strings.
What is your Billfold class?
Answer:
|