This is my output, I need the code changes so that instead of numbers it says 1=
ID: 2247460 • Letter: T
Question
This is my output, I need the code changes so that instead of numbers it says 1="Spades, 2="Diamonds", 3="Hearts, 4="Clubs", and 1=Ace, 11=Jack, 12=Queen, 13=King
Here is the code, please show me how to change this
public class Driver{
public static void main(String[] args)
{
DeckOfCards deck=new DeckOfCards();
System.out.println("Deck of Cards");
deck.printDeck();
System.out.println("Shuffling the Deck");
deck.shuffle();
Card dealtCard= deck.dealCard();
System.out.println("Card dealt Suit="+dealtCard.getSuit()+
"Face="+dealtCard.getFace());
System.out.println("no. of Cards dealt="+deck.getCardsDealt());
System.out.println("no. of Cards Left="+deck.getCardsLeft());
}
}
import java.util.Random;
public class DeckOfCards
{
private Card[] deckOfCards;
private int cardsDealt;
private int cardsLeft;
public DeckOfCards()
{
deckOfCards= new Card[52];
cardsDealt=0;
cardsLeft=52;
int count=0;
int i,j;
for(i=1; i<=4; i++)
{
for (j=1; j<=13; j++)
{
deckOfCards[count++]=new Card(i,j);
}
}
}
public void shuffle()
{ Random randomNumber=new Random();
deckOfCards=new Card[52];
int count=0;
while (count<=51)
{
int suits= randomNumber.nextInt(4)+1;
int face= randomNumber.nextInt(13)+1;
boolean found =false;
for (int i=0; i {
if (suits==deckOfCards[i].getSuit() && face==deckOfCards[i].getFace())
{found=true;
}
}
if (found==false)
{deckOfCards[count]=new Card (suits,face);
count++;
}
}
} public void printDeck()
{
for (int i=0;i {
System.out.println("Card" + (i+1) +"Suits=" +deckOfCards[i].getSuit()
+ "Face=" + deckOfCards[i].getFace());
}
}
public Card dealCard()
{
cardsDealt++;
cardsLeft--;
return (deckOfCards[0]);
}
public int getCardsDealt()
{
return cardsDealt;
}
public int getCardsLeft()
{
return cardsLeft;
}}
import java.util.Random;
public class Card
{
private int face;
private int suit;
public Card(int suit, int face)
{
this.suit=suit;
this.face=face;
}
public int getFace()
{return face;
}
public void SetFace(int face)
{
this.face=face;
}
public int getSuit()
{
return suit;
}
private void setSuit(int suit)
{
this.suit=suit;
}
}
Explanation / Answer
Modify Card.java to
Card.java
public class Card
{
private static String[] suits={"Spades","Diamonds","Hearts","Clubs"};
private static String[] faces={"Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"};
private int face;
private int suit;
public Card(int suit, int face)
{
this.suit=suit;
this.face=face;
}
public String getFace()
{return faces[face-1];
}
public void SetFace(int face)
{
this.face=face;
}
public String getSuit()
{
return suits[suit-1];
}
private void setSuit(int suit)
{
this.suit=suit;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.