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!

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question

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!
 
456789
SHEREHGA998HHHG7º254449
10
11
12
13
14
15
16
17
18
19
20
21
22
23
26
30
31
32
33
34
35
36
37
38
39
40
41
43
46
public class FaceUpCard extends Card {
private boolean faceUp;
/**
* Create a new FaceUpCard with number and suit
* @param number the card number
* @param suit the card suit
*/
public FaceUpCard (int number, String suit) {
super(number, suit);
faceUp = false;
}
/**
* Returns whether card is face up
*/
public boolean is FaceUp() {
return faceUp;
}
/**
* Flips a card from face-down to face-up or face-up to face-down
*/
public void flip() {
faceUp ! faceUp;
}
/**
* Returns the card's value in the FaceUp game
* Number cards have their number as the value
*Ace is 11, and Jack, Queen, and King are 10
*/
public int get CardValue() {
// TODO: fill in method definition; replace placeholder on next line
return 0;
}
/**
* Returns whether card is a red card, ie with suit "hearts" or "diamonds"
*/
public boolean isRedCard() {
// TODO: fill in method definition; replace placeholder on next line
return false;
}
Transcribed Image Text:456789 SHEREHGA998HHHG7º254449 10 11 12 13 14 15 16 17 18 19 20 21 22 23 26 30 31 32 33 34 35 36 37 38 39 40 41 43 46 public class FaceUpCard extends Card { private boolean faceUp; /** * Create a new FaceUpCard with number and suit * @param number the card number * @param suit the card suit */ public FaceUpCard (int number, String suit) { super(number, suit); faceUp = false; } /** * Returns whether card is face up */ public boolean is FaceUp() { return faceUp; } /** * Flips a card from face-down to face-up or face-up to face-down */ public void flip() { faceUp ! faceUp; } /** * Returns the card's value in the FaceUp game * Number cards have their number as the value *Ace is 11, and Jack, Queen, and King are 10 */ public int get CardValue() { // TODO: fill in method definition; replace placeholder on next line return 0; } /** * Returns whether card is a red card, ie with suit "hearts" or "diamonds" */ public boolean isRedCard() { // TODO: fill in method definition; replace placeholder on next line return false; }
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT