In Java Write a complete program that implements the functionality of a deck of cards. In writing your program, use the provided DeckDriver and Card classes shown below. Write your own Deck class so that it works in conjunction with the two given classes. Use anonymous objects where appropriate. Deck class details: Use an ArrayList to store Card objects. Deck constructor: The Deck constructor should initialize your ArrayList with the 52 cards found in a standard deck. Each card is a Card object. Each Card object contains two instance variables ─ num and suit. Study the Card class definition below for details. dealCard: This method removes the highest-indexed card in the ArrayList and returns it. In general, a method should not do more than what it’s supposed to do. Thus, dealCard should not print anything. toString: This method returns the deck’s contents using the format shown in the output session. In particular, note that toString should insert a newline after every fifth card. Hint: In coming up with a return value, use a String local variable. As you generate card values and newlines, concatenate those items to your local variable using the += operator. Write your code such that the following classes produce the output shown in the subsequent output. Output: 13S 12S 1C 2C 3C 4C 5C 6C 7C 8C 9C 10C 11C 12C 13C 1D 2D 3D 4D 5D 6D 7D 8D 9D 10D 11D 12D 13D 1H 2H 3H 4H 5H 6H 7H 8H 9H 10H 11H 12H 13H 1S 2S 3S 4S 5S 6S 7S 8S 9S 10S 11S   /************************************************************* * DeckDriver.java * * This class tests the Deck class. *************************************************************/ public class DeckDriver { public static void main(String[] args) { Deck deck = new Deck(); System.out.println(deck.dealCard()); System.out.println(deck.dealCard()); System.out.println(); System.out.println(deck); } // end main } // end DeckDriver class /**************************************************************** * Card.java * * * This class stores a Card's information. ****************************************************************/ public class Card { private int num; // hold a number between 1 and 13 private char suit; // holds 'C' for clubs, 'D' for diamonds, // 'H' for hearts, 'S' for spades //************************************************** public Card(int num, char suit) { this.num = num; this.suit = suit; } // end Card constructor //************************************************** // Return the card's value in the form of a concatenated // number and character. // For example, 1C = ace of clubs, 12H = queen of hearts. public String toString() { return Integer.toString(num) + suit; } } // end class Card

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

In Java

Write a complete program that implements the functionality of a deck of cards. In writing your program,
use the provided DeckDriver and Card classes shown below. Write your own Deck class so that it
works in conjunction with the two given classes. Use anonymous objects where appropriate.
Deck class details:
Use an ArrayList to store Card objects.
Deck constructor:
The Deck constructor should initialize your ArrayList with the 52 cards found in a standard
deck. Each card is a Card object. Each Card object contains two instance variables ─ num and
suit. Study the Card class definition below for details.
dealCard:
This method removes the highest-indexed card in the ArrayList and returns it. In general, a
method should not do more than what it’s supposed to do. Thus, dealCard should not print
anything.
toString:
This method returns the deck’s contents using the format shown in the output session. In particular,
note that toString should insert a newline after every fifth card. Hint: In coming up with a return
value, use a String local variable. As you generate card values and newlines, concatenate those
items to your local variable using the += operator.
Write your code such that the following classes produce the output shown in the subsequent output.

Output:
13S
12S
1C 2C 3C 4C 5C
6C 7C 8C 9C 10C
11C 12C 13C 1D 2D
3D 4D 5D 6D 7D
8D 9D 10D 11D 12D
13D 1H 2H 3H 4H
5H 6H 7H 8H 9H
10H 11H 12H 13H 1S
2S 3S 4S 5S 6S
7S 8S 9S 10S 11S

 

/************************************************************* * DeckDriver.java * * This class tests the Deck class. *************************************************************/ public class DeckDriver { public static void main(String[] args) { Deck deck = new Deck(); System.out.println(deck.dealCard()); System.out.println(deck.dealCard()); System.out.println(); System.out.println(deck); } // end main } // end DeckDriver class /**************************************************************** * Card.java * * * This class stores a Card's information. ****************************************************************/ public class Card { private int num; // hold a number between 1 and 13 private char suit; // holds 'C' for clubs, 'D' for diamonds, // 'H' for hearts, 'S' for spades //************************************************** public Card(int num, char suit) { this.num = num; this.suit = suit; } // end Card constructor //************************************************** // Return the card's value in the form of a concatenated // number and character. // For example, 1C = ace of clubs, 12H = queen of hearts. public String toString() { return Integer.toString(num) + suit; } } // end class Card

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Array
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