Practice Questions on Enumerations. 1. Create an enum called Suit that contains constants for the four...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Practice Questions on Enumerations. 1. Create an enum called Suit that contains constants for the four suits in a standard deck of cards (Clubs, Diamonds, Hearts, and Spades). 2. Create an enum called Rank that contains constants for each of the 13 ranks of cards found in a standard deck of cards. For example: TWO, FIVE, JACK, KING, QUEEN, ACE. 3. a. Modify the Suit enum: Assign a number to each suit (1 to 4), a display name for each suit, and a unicode character code for the suit's symbol. The unicode values for each suite are in the table below. Make sure you add the appropriate data members, accessor methods, and a constructor. Unicode Values for Suit Symbols(store in char datatype) Clubs - '\u2663' Diamonds - '\u2662' Hearts- '\u2661' Spades- '\u2660' 3. b. Modify the Rank enum: Assign a numeric value to each card rank (Jacks are 11, Queens are 12, Kings are 13, and Aces are 1), a name for each card (e.g. "Two", "Five", "Jack", "Ace"), and a short name for each card (e.g "2", "5", "J", "A"). Add the appropriate data members, accessor methods, and a constructor. 3. c. Create a regular class called Card with the following members: Class: Card Data Members: - rank: Rank - suit: Suit Methods: + Card() + Card(rank:Rank, suit:Suit) + setRank(rank:Rank) : void + getRank() Rank +setSuit(suit:Suit) : void + getSuit() : Suit + toString() String +shortString(): String The mutator methods don't require validation since you can't pass anything invalid into the parameters: just assign the parameter to the data member. The toString() method should return a String representation of the card in the form: RankName of SuitName For example, "Jack of Clubs", "Two of Diamonds". The shortString() method should return a shorter String representation of the card in the form: ShortRankSuitSymbol For example: J or 2 3. d. Create a regular class called DeckOfCards with the following members: Class: DeckOfCards Data Members: - cards: Card[] Methods: + DeckOfCards() - init() : void + pickCard() Card + toString() String The array of cards should have 52 elements for Card objects. The DeckOfCards() constructor only needs to call the init() method. The init() method uses nested loops to load the cards array with one of each card in a standard card deck (e.g. one of each card rank with each suit). The pickCard() method generates a random array index and returns the Card object at that index in the cards array. The toString() method returns a String containing the list of Card objects in the cards array (see sample program and output below). Sample main() method code using the DeckOfCards object: DeckOfCards deck = new DeckOfCards(); System.out.println("My Deck of Cards:"); System.out.println(deck); System.out.println(" Random Card:"); Card c deck.pickCard(); = System.out.println(c.shortString()); Practice Questions on Enumerations. 1. Create an enum called Suit that contains constants for the four suits in a standard deck of cards (Clubs, Diamonds, Hearts, and Spades). 2. Create an enum called Rank that contains constants for each of the 13 ranks of cards found in a standard deck of cards. For example: TWO, FIVE, JACK, KING, QUEEN, ACE. 3. a. Modify the Suit enum: Assign a number to each suit (1 to 4), a display name for each suit, and a unicode character code for the suit's symbol. The unicode values for each suite are in the table below. Make sure you add the appropriate data members, accessor methods, and a constructor. Unicode Values for Suit Symbols(store in char datatype) Clubs - '\u2663' Diamonds - '\u2662' Hearts- '\u2661' Spades- '\u2660' 3. b. Modify the Rank enum: Assign a numeric value to each card rank (Jacks are 11, Queens are 12, Kings are 13, and Aces are 1), a name for each card (e.g. "Two", "Five", "Jack", "Ace"), and a short name for each card (e.g "2", "5", "J", "A"). Add the appropriate data members, accessor methods, and a constructor. 3. c. Create a regular class called Card with the following members: Class: Card Data Members: - rank: Rank - suit: Suit Methods: + Card() + Card(rank:Rank, suit:Suit) + setRank(rank:Rank) : void + getRank() Rank +setSuit(suit:Suit) : void + getSuit() : Suit + toString() String +shortString(): String The mutator methods don't require validation since you can't pass anything invalid into the parameters: just assign the parameter to the data member. The toString() method should return a String representation of the card in the form: RankName of SuitName For example, "Jack of Clubs", "Two of Diamonds". The shortString() method should return a shorter String representation of the card in the form: ShortRankSuitSymbol For example: J or 2 3. d. Create a regular class called DeckOfCards with the following members: Class: DeckOfCards Data Members: - cards: Card[] Methods: + DeckOfCards() - init() : void + pickCard() Card + toString() String The array of cards should have 52 elements for Card objects. The DeckOfCards() constructor only needs to call the init() method. The init() method uses nested loops to load the cards array with one of each card in a standard card deck (e.g. one of each card rank with each suit). The pickCard() method generates a random array index and returns the Card object at that index in the cards array. The toString() method returns a String containing the list of Card objects in the cards array (see sample program and output below). Sample main() method code using the DeckOfCards object: DeckOfCards deck = new DeckOfCards(); System.out.println("My Deck of Cards:"); System.out.println(deck); System.out.println(" Random Card:"); Card c deck.pickCard(); = System.out.println(c.shortString());
Expert Answer:
Answer rating: 100% (QA)
Based on the provided practice questions we need to define enumerations for card suits and ranks and create classes for a card and a deck of cards in ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
You draw two cards from a standard deck of 52 cards without replacing the first one before drawing the second. (a) Are the outcomes on the two cards independent? Why? (b) Find P(Ace on 1st card and...
-
Debbie Walker earns a salary of $4,000 per month during the year.Employment Insurance taxes (EI) are 1.88% of the first $49,500 in earnings. The Canadian Pension Plan (CPP) rate is 4.95% of the first...
-
A 1 M solution of Cu(NO3)2 is placed in a beaker with a strip of Cu metal. A 1 M solution of SnSO4 is placed in a second beaker with a strip of Sn metal. A salt bridge connects the two beakers, and...
-
Brent SA owns equipment that cost 80,000 and has a useful life of 8 years with no residual value. On January 1, 2022, Brent leases the equipment to Havaci ASA for 1 year for one rental payment of...
-
Chase Publishing Company purchased the copyright to a financial textbook for $\$ 25,000$. Although the author thought the book would serve academia for 10 years, the reality is that the typical life...
-
Easy-Tech Software Corporation is evaluating the production of a new software product to compete with the popular word processing software currently available. Annual fixed costs of producing the...
-
Consider a reservoir filled with water of uniform density po and subject to the gravi- tational force. One side of the reservoir is confined by a dam wall of height h and width W, as shown in the...
-
Blue Fire Limited ("BFL") is a jewellery retailer in Hong Kong operates 50 retail outlets. In recent years, BFL has experienced rapid growth and expanded its retail network from physical outlets to...
-
What payment streams exist?
-
Identify different public charges.
-
What is the difference between effectiveness and efficiency related to each other?
-
Why are administrative prices useful?
-
Why is it important to operationalize?
-
You are given the following cost function: Cost equals 0.2 q cubed minus 6 q squared plus 80 q plus 150 Cost = 0.2q 3 ? 6 q 2 + 80 q +150. Marginal cost is: 0.6 q squared minus 12 q plus 80 0.6q 2 ?...
-
In what ways does a well-designed enterprise search software vary from popular search engines (e.g., Bing, DuckDuckGo, and Google)?
-
A new business graduate with one subject of accounting prepared the financial statements below for Amirs Delivery Service at the end of the first year of operations. Additional analysis revealed the...
-
Financial balances for the car hire business of Terry's Wedding Cars on 31 March 2024 are provided below in a table in accounting equation form similar to the chapter illustrations. During April, the...
-
Eliza Perry obtained registration to practice as an aesthetic nurse, and spent the month of July 2024 setting up her business E. Perry, Naturals. Eliza prepared a new statement of financial position...
Study smarter with the SolutionInn App