Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hallmark has asked you to implement a system for them so that a user can choose

ID: 3650198 • Letter: H

Question

Hallmark has asked you to implement a system for them so that a user can choose from a list of available cards. There are 9 cards to choose from: Christmas, Valentine's, Birthday, Get well soon, Anniversary, New baby, Thank you, Congratulations, and blank. Your program asks the user who the card is for and who it is from. If it is a birthday card, it also asks how old the recipient is. If it is a blank card, it asks what personal message the sender would like to include. If it is a Valentine's day card it personalizes the card by adding XOs to the end of the card (hugs and kisses) based on the length of the recipient's name. Create the cards by extending an abstract class Card and using an abstract method called makeCard that is defined for each card.

Explanation / Answer

abstract class Game { protected int playersCount; abstract void initializeGame(); abstract void makePlay(int player); abstract boolean endOfGame(); abstract void printWinner(); /* A template method : */ public final void playOneGame(int playersCount) { this.playersCount = playersCount; initializeGame(); int j = 0; while (!endOfGame()) { makePlay(j); j = (j + 1) % playersCount; } printWinner(); } } //Now we can extend this class in order //to implement actual games: class Monopoly extends Game { /* Implementation of necessary concrete methods */ void initializeGame() { // Initialize players // Initialize money } void makePlay(int player) { // Process one turn of player } boolean endOfGame() { // Return true if game is over // according to Monopoly rules } void printWinner() { // Display who won } /* Specific declarations for the Monopoly game. */