M 1 Exercises Solution



For maximum learning effectiveness, please check the [answers](../Answers/M1-Answers.md) only after giving the problems an honest try.

1. Implement class `Card` as a single enumerated type. For the purpose of the Solitaire application, does this look like a superior or inferior solution to version 7 of class `Card` seen in class? Why? Try writing down your answer in specific terms using terminology seen in the book.

2. Extend version 7 of class `Card` to support the concept of a “Joker” (a special card that is not in any suit) while keeping the class as well-encapsulated as possible.

3. Further extend your class to support any number of distinct jokers. For example, a “high” joker vs. a “low” joker, or even three jokers, etc. Again, try to keep things well-encapsulated and respectful of the class design guidelines seen in the reading.

4. Add a method `getCards()` to the `Deck` class that returns the cards in the deck without breaking encapsulation.

5. Create a new class called `MultiDeck` that contains a list of decks (some card games require multiple decks). Make the class copyable through a copy constructor. First, make a shallow copy of the decks contained. Use the debugger to confirm that the decks in a multi-deck are shared between an original multi-deck and its copies. Then, use deep copying to make copied multi-decks fully distinct object graphs. Use Design by Contract and the `assert` statement to clarify the class’s interface.

6. Create a UML Object Diagram of a `MultiDeck` instance.

7. Study JetUML’s [MultiLineString](https://github.com/prmr/JetUML/blob/v1.0/src/ca/mcgill/cs/stg/jetuml/framework/MultiLineString.java) class and assess the quality of its encapsulation. Is it possible to modify its state without going through its methods?

Note: this content is updated from exercises in [Introduction to Software Design with Java](https://github.com/prmr/SoftwareDesign/blob/master/modules/Module-01.md) by Martin P. Robillard

error: Content is protected !!