Using the card.java class file, write a program to simulate a Deck of Cards.  See Programming Project 8.7 (PP 8.7) from page 403 on textbook for a description of what your program needs to do.  Note that although the book description of the problem states that you should write the Card class, I do not want you to do that.  You must use the Card file exactly as it is provided (NO modifications) and only write the DeckOfCards and Driver classes.   public class Card { public final static int ACE = 1; public final static int TWO = 2; public final static int THREE = 3; public final static int FOUR = 4; public final static int FIVE = 5; public final static int SIX = 6; public final static int SEVEN = 7; public final static int EIGHT = 8; public final static int NINE = 9; public final static int TEN = 10; public final static int JACK = 11; public final static int QUEEN = 12; public final static int KING = 13; public final static int CLUBS = 1; public final static int DIAMONDS = 2; public final static int HEARTS = 3; public final static int SPADES = 4; private final static int NUM_FACES = 13; private final static int NUM_SUITS = 4; private int face, suit; private String faceName, suitName; //----------------------------------------------------------------- // Creates a random card. //----------------------------------------------------------------- public Card() { face = (int) (Math.random() * NUM_FACES) + 1; setFaceName(); suit = (int) (Math.random() * NUM_SUITS) + 1; setSuitName(); } //----------------------------------------------------------------- // Creates a card of the specified suit and face value. //----------------------------------------------------------------- public Card(int faceValue, int suitValue) { face = faceValue; setFaceName(); suit = suitValue; setSuitName(); } //----------------------------------------------------------------- // Sets the string representation of the face using its stored // numeric value. //----------------------------------------------------------------- private void setFaceName() { switch (face) { case ACE: faceName = "Ace"; break; case TWO: faceName = "Two"; break; case THREE: faceName = "Three"; break; case FOUR: faceName = "Four"; break; case FIVE: faceName = "Five"; break; case SIX: faceName = "Six"; break; case SEVEN: faceName = "Seven"; break; case EIGHT: faceName = "Eight"; break; case NINE: faceName = "Nine"; break; case TEN: faceName = "Ten"; break; case JACK: faceName = "Jack"; break; case QUEEN: faceName = "Queen"; break; case KING: faceName = "King"; break; } } //----------------------------------------------------------------- // Sets the string representation of the suit using its stored // numeric value. //----------------------------------------------------------------- private void setSuitName() { switch (suit) { case CLUBS: suitName = "Clubs"; break; case DIAMONDS: suitName = "Diamonds"; break; case HEARTS: suitName = "Hearts"; break; case SPADES: suitName = "Spades"; break; } } //----------------------------------------------------------------- // Determines if this card is higher than the parameter. The // second parameter determines if aces should be considered high // (beats a King) or low (lowest of all faces). Uses the suit // if both cards have the same face. //----------------------------------------------------------------- public boolean isHigherThan(Card card2, boolean aceHigh) { boolean result = false; if (face == card2.getFace()) { if (suit > card2.getSuit()) result = true; } else { if (aceHigh && face == ACE) result = true; else if (face > card2.getFace()) result = true; } return result; } //----------------------------------------------------------------- // Determines if this card is higher than the passed card, // assuming that aces should be considered high. //----------------------------------------------------------------- public boolean isHigherThan(Card card2) { return isHigherThan(card2, true); } //----------------------------------------------------------------- // Returns the face (numeric value) of this card. //----------------------------------------------------------------- public int getFace() { return face; } //----------------------------------------------------------------- // Returns the suit (numeric value) of this card. //----------------------------------------------------------------- public int getSuit() { return suit; } //----------------------------------------------------------------- // Returns the face (string value) of this card. //----------------------------------------------------------------- public String getFaceName() { return faceName; } //----------------------------------------------------------------- // Returns the suit (string value) of this card. //----------------------------------------------------------------- public String getSuitName() { return suitName; } //----------------------------------------------------------------- // Returns the string representation of this card, including // both face and suit. //----------------------------------------------------------------- public String toString() { return faceName + " of " + suitName; } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Using the card.java class file, write a program to simulate a Deck of Cards.  See Programming Project 8.7 (PP 8.7) from page 403 on textbook for a description of what your program needs to do.  Note that although the book description of the problem states that you should write the Card class, I do not want you to do that.  You must use the Card file exactly as it is provided (NO modifications) and only write the DeckOfCards and Driver classes.

 

public class Card
{
public final static int ACE = 1;
public final static int TWO = 2;
public final static int THREE = 3;
public final static int FOUR = 4;
public final static int FIVE = 5;
public final static int SIX = 6;
public final static int SEVEN = 7;
public final static int EIGHT = 8;
public final static int NINE = 9;
public final static int TEN = 10;
public final static int JACK = 11;
public final static int QUEEN = 12;
public final static int KING = 13;

public final static int CLUBS = 1;
public final static int DIAMONDS = 2;
public final static int HEARTS = 3;
public final static int SPADES = 4;

private final static int NUM_FACES = 13;
private final static int NUM_SUITS = 4;

private int face, suit;
private String faceName, suitName;

//-----------------------------------------------------------------
// Creates a random card.
//-----------------------------------------------------------------
public Card()
{
face = (int) (Math.random() * NUM_FACES) + 1;
setFaceName();

suit = (int) (Math.random() * NUM_SUITS) + 1;
setSuitName();
}

//-----------------------------------------------------------------
// Creates a card of the specified suit and face value.
//-----------------------------------------------------------------
public Card(int faceValue, int suitValue)
{
face = faceValue;
setFaceName();

suit = suitValue;
setSuitName();
}

//-----------------------------------------------------------------
// Sets the string representation of the face using its stored
// numeric value.
//-----------------------------------------------------------------
private void setFaceName()
{
switch (face)
{
case ACE:
faceName = "Ace";
break;
case TWO:
faceName = "Two";
break;
case THREE:
faceName = "Three";
break;
case FOUR:
faceName = "Four";
break;
case FIVE:
faceName = "Five";
break;
case SIX:
faceName = "Six";
break;
case SEVEN:
faceName = "Seven";
break;
case EIGHT:
faceName = "Eight";
break;
case NINE:
faceName = "Nine";
break;
case TEN:
faceName = "Ten";
break;
case JACK:
faceName = "Jack";
break;
case QUEEN:
faceName = "Queen";
break;
case KING:
faceName = "King";
break;
}
}

//-----------------------------------------------------------------
// Sets the string representation of the suit using its stored
// numeric value.
//-----------------------------------------------------------------
private void setSuitName()
{
switch (suit)
{
case CLUBS:
suitName = "Clubs";
break;
case DIAMONDS:
suitName = "Diamonds";
break;
case HEARTS:
suitName = "Hearts";
break;
case SPADES:
suitName = "Spades";
break;
}
}

//-----------------------------------------------------------------
// Determines if this card is higher than the parameter. The
// second parameter determines if aces should be considered high
// (beats a King) or low (lowest of all faces). Uses the suit
// if both cards have the same face.
//-----------------------------------------------------------------
public boolean isHigherThan(Card card2, boolean aceHigh)
{
boolean result = false;

if (face == card2.getFace())
{
if (suit > card2.getSuit())
result = true;
}
else
{
if (aceHigh && face == ACE)
result = true;
else
if (face > card2.getFace())
result = true;
}

return result;
}

//-----------------------------------------------------------------
// Determines if this card is higher than the passed card,
// assuming that aces should be considered high.
//-----------------------------------------------------------------
public boolean isHigherThan(Card card2)
{
return isHigherThan(card2, true);
}

//-----------------------------------------------------------------
// Returns the face (numeric value) of this card.
//-----------------------------------------------------------------
public int getFace()
{
return face;
}

//-----------------------------------------------------------------
// Returns the suit (numeric value) of this card.
//-----------------------------------------------------------------
public int getSuit()
{
return suit;
}

//-----------------------------------------------------------------
// Returns the face (string value) of this card.
//-----------------------------------------------------------------
public String getFaceName()
{
return faceName;
}

//-----------------------------------------------------------------
// Returns the suit (string value) of this card.
//-----------------------------------------------------------------
public String getSuitName()
{
return suitName;
}

//-----------------------------------------------------------------
// Returns the string representation of this card, including
// both face and suit.
//-----------------------------------------------------------------
public String toString()
{
return faceName + " of " + suitName;
}
}

 

403
Programming Projects
PP 8.6
The L&L Bank can handle up to 30 customers who have sav-
ings accounts. Design and implement a program
the
accounts. Keep track of key information and allow each customer to
that
manages
make deposits and withdrawals. Produce appropriate error messages
for invalid transactions. Hint: You may want to base your accounts
on the Account class from Chapter 4. Also provide a method to add
3 percent interest to all accounts whenever the method is invoked.
VideoNote
Developing a solution of
PP 8.5.
Create a Card class that represents a playing card with a face
value and a suit. Then create a class called DeckOf Cards that
stores 52 objects of the Card class. Include methods to shuffle
the deck, deal a card, and report the number of cards left in the
deck. The shuffle method should assume a full deck. Create
a driver class with a main method that deals each card from a
shuffled deck, printing each card as it is dealt.
PP 8.7
Write a program that reads a sequence of up to 25 pairs of
names and postal (ZIP) codes for individuals. Store the data
in an object designed to store a first name (string), last name
(string), and postal code (integer). Assume each line of input will
contain two strings followed by an integer value, each separated
by a tab character. Then, after the input has been read in, print
the list in an appropriate format to the screen.
PP 8.8
Modify the program you created in PP 8.8 to accomplish the
following:
PP 8.9
- Support the storing of additional user information: street
address (string), city (string), state (string), and 10-digit phone
number (long integer, contains area code and does not include
special characters such as '(', ')', or '-')
1 Store the data in an ArrayList object.
PP 8.10 Use the Question class from Chapter 7 to define a Quiz class.
A quiz can be composed of up to 25 questions. Define the add
method of the Quiz class to add a question to a quiz. Define the
giveQuiz method of the Quiz class to present each question in
and keep track
of the results. Define a class called QuizTime with a main method
that populates a quiz, presents it, and prints the final results.
PP 8.11 Modify your answer to PP 8.10 so that the complexity level of
the questions given in the quiz is taken into account. Overload
the giveQuiz method so that it accepts twoO integer parameters
that specify the minimum and maximum complexity levels for
the quiz questions and presents only questions in that complexity
range. Modify the main method to demonstrate this feature
one,
turn to the user, accept an answer for each
Transcribed Image Text:403 Programming Projects PP 8.6 The L&L Bank can handle up to 30 customers who have sav- ings accounts. Design and implement a program the accounts. Keep track of key information and allow each customer to that manages make deposits and withdrawals. Produce appropriate error messages for invalid transactions. Hint: You may want to base your accounts on the Account class from Chapter 4. Also provide a method to add 3 percent interest to all accounts whenever the method is invoked. VideoNote Developing a solution of PP 8.5. Create a Card class that represents a playing card with a face value and a suit. Then create a class called DeckOf Cards that stores 52 objects of the Card class. Include methods to shuffle the deck, deal a card, and report the number of cards left in the deck. The shuffle method should assume a full deck. Create a driver class with a main method that deals each card from a shuffled deck, printing each card as it is dealt. PP 8.7 Write a program that reads a sequence of up to 25 pairs of names and postal (ZIP) codes for individuals. Store the data in an object designed to store a first name (string), last name (string), and postal code (integer). Assume each line of input will contain two strings followed by an integer value, each separated by a tab character. Then, after the input has been read in, print the list in an appropriate format to the screen. PP 8.8 Modify the program you created in PP 8.8 to accomplish the following: PP 8.9 - Support the storing of additional user information: street address (string), city (string), state (string), and 10-digit phone number (long integer, contains area code and does not include special characters such as '(', ')', or '-') 1 Store the data in an ArrayList object. PP 8.10 Use the Question class from Chapter 7 to define a Quiz class. A quiz can be composed of up to 25 questions. Define the add method of the Quiz class to add a question to a quiz. Define the giveQuiz method of the Quiz class to present each question in and keep track of the results. Define a class called QuizTime with a main method that populates a quiz, presents it, and prints the final results. PP 8.11 Modify your answer to PP 8.10 so that the complexity level of the questions given in the quiz is taken into account. Overload the giveQuiz method so that it accepts twoO integer parameters that specify the minimum and maximum complexity levels for the quiz questions and presents only questions in that complexity range. Modify the main method to demonstrate this feature one, turn to the user, accept an answer for each
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 6 images

Blurred answer
Knowledge Booster
Math class and its different methods
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education