Using Jave and JOptionPane I. INTRODUCTION: This project applies the concepts of
ID: 3847062 • Letter: U
Question
Using Jave and JOptionPane
I. INTRODUCTION: This project applies the concepts of random number generation, multi-dimensional array and bit-mapped technique. ll. DESCRIPTION A deck of playing cards has four suits which are Spade (A Mu2660''), Heart (v-mu2665), Diamond -u2666), and Club 1u2663). Each suit has 13 cards in the order of 12, 3 9, 10, J, Q, K, A) and this is called the rank of the card. Most card games do not rank suits; the ace of clubs is just as good as the ace of spades However, there are occasions that the ranking of the suits needs to be decided. Please be reminded that no standard of ranking of suits exits. However, in this project we are going to use the Reverse Alphabetical order convention: clubs (lowest), followed by diamonds, hearts, and spades (highest). This ranking is also used in the game of bridge. Ill. ASSIGNMENT Write a JAVA program according to produce the output similar to the following according to the steps specified below: EAST A 10 3 V: A 9 8 A Q J Q 10 86 NORTH V: K 10 7 10 9 8 7 6 2 4 J 4 3 WEST 4 Q 6 5 6 5 4 3 2 4 3 K 7 2 SOUTH K J 9 8 7 4. Q J K 5 4 A 9 5 OKExplanation / Answer
public class DeckOfCards2 {
public static void main(String[] args) {
int[] deck = new int[52];
String[] suits = {"Spades", "Hearts", "Diamonds", "Clubs"};
String[] ranks = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
// Initialize cards
for (int i = 0; i < deck.length; i++) {
deck[i] = i;
}
// Shuffle the cards
for (int i = 0; i < deck.length; i++) {
int index = (int)(Math.random() * deck.length);
int temp = deck[i];
deck[i] = deck[index];
deck[index] = temp;
}
// Display the all the cards
for (int i = 0; i < 52; i++) {
String suit = suits[deck[i] / 13];
String rank = ranks[deck[i] % 13];
System.out.println( rank + " of " + suit);
}
}
}
Now trying to split it up into 3 classes. I am getting red sqiggle lines on ALL my deck/suit variables on my DeckOfCards class. I dont know how to fix it.
public class DeckOfCards {
private Card theCard;
private int remainingCards = 52;
DeckOfCards() {
theCard = new Card();
}
public void shuffle(){
for (int i = 0; i < deck.length; i++) {
int index = (int)(Math.random() deck.length);
int temp = deck[i];
deck[i] = deck[index];
deck[index] = temp;
remainingCards--;
}
}
public void deal(){
for (int i = 0; i < 52; i++) {
String suit = suits[deck[i] / 13];
String rank = ranks[deck[i] % 13];
System.out.println( rank + " of " + suit);
System.out.println("Remaining cards: " + remainingCards);
}
}
}
Card class:
public class Card {
int[] deck = new int[52];
String[] suits = {"Spades", "Hearts", "Diamonds", "Clubs"};
String[] ranks = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
Card() {
for (int i = 0; i < deck.length; i++) {
deck[i] = i;
}
}
}
Dealer class
public class Dealer {
public static void main(String[]args){
System.out.println("The deck will randomly print out a card from a full deck each time");
DeckOfCards player = new DeckOfCards();
player.deal();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.