Question: home / study / engineering / computer science / computer science questions and answers / in chapter 8 you created a class named fulldeck that
home / study / engineering / computer science / computer science questions and answers / in chapter 8 you created a class named fulldeck that implemented a 52-element array that represented... Question: In chapter 8 you created a class named FullDeck that implemented a 52-element array that represen... in chapter 8 you created a class named FullDeck that implemented a 52-element array that represented each card in a standard deck of playing cards. Now, create an enumeration that holds the four suits SPADES, HEARTS, DIAMONDS, and CLUBS. Save the enumeration in a file named Suit.java. Modify the Card class from Chapter 8 to use the enumeration, and save the class as Card2.java. Modify the FullDeck application to use the new CARD class and save the application as FullDeck2.java Chapter 8 - Card Class public class Card { private String suit; private int value; private String rank; final int HIGH_VAL = 13; final int LOW_VAL = 1; final int HIGH = 4; public String getSuit() { return suit; } public int getValue() { return value; } public String getRank() { return rank; } public void setSuit(String s) { suit = s; } public void setValue(int v) { if(v >= LOW_VAL && v <= HIGH_VAL) value = v; else value = LOW_VAL; if(value == 1) rank = "Ace"; else if(value == 11) rank ="Jack"; else if(value == 12) rank = "Queen"; else if(value == 13) rank = "King"; else rank = Integer.toString(value); } } Chapter 8 - FullDeck public class FullDeck { public static void main(String[] args) { final int CARDS_IN_DECK = 52; Card[] card = new Card[CARDS_IN_DECK]; final int HIGH_SUIT = 4; int x; int suit, value; suit = 1; value = 1; for(x = 0; x < CARDS_IN_DECK; ++x) { card[x] = new Card(); if(suit == 1) card[x].setSuit("Spades"); else if(suit == 2) card[x].setSuit("Hearts"); else if(suit == 3) card[x].setSuit("Diamonds"); else card[x].setSuit("Clubs"); card[x].setValue(value); System.out.println(card[x].getRank() + " of " + card[x].getSuit()); ++value; if(value > card[x].HIGH_VAL) { ++suit; value = 1; } } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
