FaceUp card game In this assignment we will implement a made-up card game we'll call FaceUp. When the game starts, you deal five cards face down. Your goal is to achieve as high a score as possible. Your score only includes cards that are face up. Red cards (hearts and diamonds) award positive points, while black cards (clubs and spades) award negative points. Cards 2-10 have points worth their face value. Cards Jack, Queen, and King have value 10, and Ace is 11. The game is played by flipping over cards, either from face-down to face-up or from face-up to face-down. As you play, you are told your total score (ie, total of the face-up cards) and the total score of the cards that are face down. The challenge is that you only get up to a fixed number of flips and then the game is over. Here is an example of the output from playing the game: FACE-DOWN | FACE-DOWN | FACE-DOWN | FACE-DOWN | FACE-DOWN Face up total: 0 Face down total: -5 Number of flips left: 5 Pick a card to flip between 1 and 5 (-1 to end game): 1 Queen of hearts | FACE-DOWN | FACE-DOWN | FACE-DOWN | FACE-DOWN Face up total: 10 Face down total: -15 Number of flips left: 4 Pick a card to flip between 1 and 5 (-1 to end game): 2 Queen of hearts | Jack of clubs | FACE-DOWN | FACE-DOWN | FACE-DOWN Face up total: 0 Face down total: -5 Number of flips left: 3 Pick a card to flip between 1 and 5 (-1 to end game): 2 Queen of hearts | FACE-DOWN | FACE-DOWN | FACE-DOWN | FACE-DOWN Face up total: 10 Face down total: -15 Number of flips left: 2 Pick a card to flip between 1 and 5 (-1 to end game): 10 10 is not a valid card Queen of hearts | FACE-DOWN | FACE-DOWN | FACE-DOWN | FACE-DOWN Face up total: 10 Face down total: -15 Number of flips left: 2 Pick a card to flip between 1 and 5 (-1 to end game): 0 0 is not a valid card Queen of hearts | FACE-DOWN | FACE-DOWN | FACE-DOWN | FACE-DOWN Face up total: 10 Face down total: -15 Number of flips left: 2 Pick a card to flip between 1 and 5 (-1 to end game): 5 Queen of hearts | FACE-DOWN | FACE-DOWN | FACE-DOWN | 3 of hearts Face up total: 13 Face down total: -18 Number of flips left: 1 Pick a card to flip between 1 and 5 (-1 to end game): -1 ---------------------- Your score: 13 Best possible score: 15 At each point where the program asks the user to pick a card, the game waits for user input. Here is FaceUpHand. And FaceUpCard is attached down below. /** * Keeps track of the cards and and answers questions * for the FaceUp card game. * * Red cards (hearts and diamonds) award positive points, while black cards * (clubs and spades) award negative points. Cards 2-10 have points worth * their face value; Jack, Queen and King are 10; and Ace is 11. */ public class FaceUpHand { privateFaceUpCard[] cards; /** * Create a new FaceUp card game state, which consists of the * array cards of size numCards * * @param numCards number of cards in the game */ publicFaceUpHand(intnumCards) { // TODO: fill in method definition to initialize the cards array // 1. set the instance variable cards equal to a new array (size numCards) of type FaceUpCard // 2. create a variable dealer of type CardDealer for 1 deck // 3. loop through the cards array and set each value to dealer.next() } /** * Return the FaceUpCard in position cardIndex of cards * * @return the element of cards specified by cardIndex */ publicFaceUpCardgetCard(intcardIndex) { // TODO: fill in method definition; replace placeholder on next line returnnull; } /** * Flip the card over at this index * Card indices start at 0 and go up the cards.length-1 * * @param cardIndex the index of the card to flip over */ publicvoidflipCard(intcardIndex) { // TODO: fill in method definition } /** * Calculate the best possible score for the current cards * * @return the optimal score */ publicintcalculateOptimal() { // TODO: fill in method definition; replace placeholder on next line return0; } /** * Calculate the total score for the cards that are face up * * @return the total score for face-up cards */ publicintfaceUpTotal() { // Hint: use getCardValue() and remember red cards have positive value // and black cards have negative value // TODO: fill in method definition; replace placeholder on next line return0; } /** * Calculate the total score for the cards that are face down * * @return the total score for face-down cards */ publicintfaceDownTotal() { // Hint: use getCardValue() and remember red cards have positive value // and black cards have negative value // TODO: fill in method definition; replace placeholder on next line return0; } // TODO: add a toString method here!
FaceUp card game
In this assignment we will implement a made-up card game we'll call FaceUp. When the game starts, you deal five cards face down. Your goal is to achieve as high a score as possible. Your score only includes cards that are face up. Red cards (hearts and diamonds) award positive points, while black cards (clubs and spades) award negative points. Cards 2-10 have points worth their face value. Cards Jack, Queen, and King have value 10, and Ace is 11.
The game is played by flipping over cards, either from face-down to face-up or from face-up to face-down. As you play, you are told your total score (ie, total of the face-up cards) and the total score of the cards that are face down. The challenge is that you only get up to a fixed number of flips and then the game is over.
Here is an example of the output from playing the game:
FACE-DOWN | FACE-DOWN | FACE-DOWN | FACE-DOWN | FACE-DOWN Face up total: 0 Face down total: -5 Number of flips left: 5 Pick a card to flip between 1 and 5 (-1 to end game): 1 Queen of hearts | FACE-DOWN | FACE-DOWN | FACE-DOWN | FACE-DOWN Face up total: 10 Face down total: -15 Number of flips left: 4 Pick a card to flip between 1 and 5 (-1 to end game): 2 Queen of hearts | Jack of clubs | FACE-DOWN | FACE-DOWN | FACE-DOWN Face up total: 0 Face down total: -5 Number of flips left: 3 Pick a card to flip between 1 and 5 (-1 to end game): 2 Queen of hearts | FACE-DOWN | FACE-DOWN | FACE-DOWN | FACE-DOWN Face up total: 10 Face down total: -15 Number of flips left: 2 Pick a card to flip between 1 and 5 (-1 to end game): 10 10 is not a valid card Queen of hearts | FACE-DOWN | FACE-DOWN | FACE-DOWN | FACE-DOWN Face up total: 10 Face down total: -15 Number of flips left: 2 Pick a card to flip between 1 and 5 (-1 to end game): 0 0 is not a valid card Queen of hearts | FACE-DOWN | FACE-DOWN | FACE-DOWN | FACE-DOWN Face up total: 10 Face down total: -15 Number of flips left: 2 Pick a card to flip between 1 and 5 (-1 to end game): 5 Queen of hearts | FACE-DOWN | FACE-DOWN | FACE-DOWN | 3 of hearts Face up total: 13 Face down total: -18 Number of flips left: 1 Pick a card to flip between 1 and 5 (-1 to end game): -1 ---------------------- Your score: 13 Best possible score: 15At each point where the program asks the user to pick a card, the game waits for user input.
Here is FaceUpHand. And FaceUpCard is attached down below.


Step by step
Solved in 2 steps









