Question
Write a class Card. A Card has the following private attributes: A String suit. An int value. There are four possible options for suits: hearts,
Write a class Card. A Card has the following private attributes:
A String suit.
An int value.
There are four possible options for suits: hearts, spades, clubs, and diamonds. There are 13 possible options for the value: ace, two, three, four, five, six, seven, eight, nine, ten, jack, queen, and king. For this assignment, we will represent the value using an int which has a value between 1 and 13. The suit will be represented using a String. The Card class also contains the following public methods: A constructor that takes as input an int for the value and a String for the suit, and initializes the attributes accordingly. The inputs are considered to be valid if they create a card of value between 1 and 13 (both included) and of suit equal to either hearts, spades, clubs, or diamonds (please ignore capitalization). If the input are invalid, then the constructor should throw an IllegalArgumentException explaining that no card of such type can be created. getSuit() which returns the suit of the card. getValue() which returns the value of the card. print() which takes nothing as input and prints the content of the card. For example 3 of spades or 13 of clubs. Note that it is not necessary to print the words such as king or queen. You can leave them as 13 or 12 if you want to.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started