Question: I am working on this assignment for my Java Computer Science Class - and it is divided into two parts The first class I entered
I am working on this assignment for my Java Computer Science Class - and it is divided into two parts
The first class I entered "Deck" is like this
public class Deck { private Card[] deck; private int cardsUsed; public Deck() { this(false); }
public Deck(boolean includeJokers) { if (includeJokers) deck = new Card[54]; else deck = new Card[52]; int cardCt = 0; for ( int suit = 0; suit <= 3; suit++ ) { for ( int value = 1; value <= 13; value++ ) { deck[cardCt] = new Card(value,suit); cardCt++; } } if (includeJokers) { deck[52] = new Card(1,Card.JOKER); deck[53] = new Card(2,Card.JOKER); } cardsUsed = 0; }
public void shuffleDeck() { for ( int i = deck.length-1; i > 0; i-- ) { int rand = (int)(Math.random()*(i+1)); Card temp = deck[i]; deck[i] = deck[rand]; deck[rand] = temp; } cardsUsed = 0; }
public int cardsLeft() { return deck.length - cardsUsed; }
public Card dealCard() { if (cardsUsed == deck.length) throw new IllegalStateException("No cards are left in the deck."); cardsUsed++; return deck[cardsUsed - 1]; }
}
and I am getting this error when I place it in a code runner:
Main.java:121: error: constructor Card in class Card cannot be applied to given types; deck[cardCt] = new Card(value,suit); ^ required: String,String,int found: int,int reason: actual and formal argument lists differ in length Main.java:126: error: cannot find symbol deck[52] = new Card(1,Card.JOKER); ^ symbol: variable JOKER location: class Card Main.java:127: error: cannot find symbol deck[53] = new Card(2,Card.JOKER); ^ symbol: variable JOKER location: class Card Main.java:303: error: cannot find symbol Card c = d.getTopCard(); ^ symbol: method getTopCard() location: variable d of type Deck Note: Main.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 4 errors
Here is the transcript of the asssignment instructions, I'd really appreciate the help! Thanks!!
Assignment 5 - Shuffle
In this lab you will simulate the playing of a simple card game. Start by downloading two starter files: Card.java and Deck.java. The Card class should not be changed. You will add one method to the Deck class.
This assignment should be submitted in two classes, each with a separate code runner box. The first class, Deck, will be a modification of the class we have provided. You will need to implement the shuffleDeck method in order for this class to be accepted.
The second class, Main, will use the Card class and your modified Deck class to create a shuffled Deck object and deal the two hands. The hands should be dealt in alternating order, starting with the first hand. Each hand should have five cards. As the cards are dealt into each hand they should be removed from the deck.
For example, each hand is shown for the following Deck.
Seven of spades <- Index 0, top card Queen of spades <- Index 1, etc. Ten of spades Eight of spades Three of spades King of hearts Queen of hearts Jack of clubs Four of clubs Eight of clubs King of diamonds Seven of hearts
| Hand 1: | Hand 2: |
|---|---|
| Seven of spades | Queen of spades |
| Ten of spades | Eight of spades |
| Three of spades | King of hearts |
| Queen of hearts | Jack of clubs |
| Four of clubs | Eight of clubs |
Also, all of these cards should be removed from the deck.
After dealing the hand, Main should use the point value of each card to calculate the total point value of each hand. The hand with the highest point value wins. In the case of a draw, the second hand wins. In this game ace = 1, jack = 11, queen = 12, and king = 13. In the deck the card in the first position (index 0) is the top of the deck.
Lastly, Main will declare the winning hand. See the following sample run of Main for the exact format that will be expected by the code runner.
Sample Run of Main:
Hand 1 (total points 22) Three of clubs (point value = 3) Two of clubs (point value = 2) Six of hearts (point value = 6) Ten of hearts (point value = 10) Ace of spades (point value = 1) Hand 2 (total points 27) Four of spades (point value = 4) Ten of clubs (point value = 10) Three of diamonds (point value = 3) Eight of diamonds (point value = 8) Two of hearts (point value = 2) Hand 2 wins!
Here is the Card Class:
import java.util.ArrayList;
//Define a class Card
class Card
{
//Declare variables
public final static int SPADES = 0;
//Declare variables
public final static int HEARTS = 1;
//Declare variables
public final static int DIAMONDS = 2;
//Declare variables
public final static int CLUBS = 3;
//Declare variables
public final static int JOKER = 4;
//Declare variables
public final static int ACE = 1;
//Declare variables
public final static int JACK = 11;
//Declare variables
public final static int QUEEN = 12;
//Declare variables
public final static int KING = 13;
//Declare variables
private final int suit;
//Declare variables
private final int value;
//Define a constructor
public Card()
{
//Set value
suit = JOKER;
//Set value
value = 1;
}
//Define a constructor Card
public Card(int theValue, int theSuit)
{
//If value is not given
if (theSuit != SPADES && theSuit != HEARTS && theSuit != DIAMONDS &&
theSuit != CLUBS && theSuit != JOKER)
//Display message
throw new IllegalArgumentException("Illegal playing card suit");
//If value is less than 1 or greater than 13
if (theSuit != JOKER && (theValue < 1 || theValue > 13))
//Display message
throw new IllegalArgumentException("Illegal playing card value");
//Set value
value = theValue;
//Set value
suit = theSuit;
}
//Define method getSuitName()
public String getSuitName()
{
//If suit is 0
if(getSuit()==0)
//Return value
return "SPADES";
//If suit is 1
if(getSuit()==1)
//Return value
return "HEARTS";
//If suit is 2
if(getSuit()==2)
//Return value
return "DIAMONDS";
//If suit is 3
if(getSuit()==3)
//Return value
return "CLUBS";
//If suit is 4
if(getSuit()==4)
//Return value
return "JOKER";
//If suit is 1
if(getSuit()==1)
//Return value
return "ACE";
//If suit is 11
if(getSuit()==11)
//Return value
return "JACK";
//If suit is 12
if(getSuit()==12)
//Return value
return "QUEEN";
//If suit is 13
if(getSuit()==13)
//Return value
return "KING";
//Else
else
//Return
return "";
}
//Define method getValue1()
public String getValue1()
{
//If value is 1
if(getValue()==1)
//Return
return "ACE";
//If value is 2
if(getValue()==2)
//Return
return "Two";
//If value is 3
if(getValue()==3)
//Return
return "Three";
//If value is 4
if(getValue()==4)
//Return
return "Four";
//If value is 5
if(getValue()==5)
//Return
return "Five";
//If value is 6
if(getValue()==6)
//Return
return "Six";
//If value is 7
if(getValue()==7)
//Return
return "Seven";
//If value is 8
if(getValue()==8)
//Return
return "Eight";
//If value is 9
if(getValue()==9)
//Return
return "Nine";
//If value is 10
if(getValue()==10)
//Return
return "Ten";
//If value is 11
if(getValue()==11)
//Return
return "JACK";
//If value is 12
if(getValue()==12)
//Return
return "QUEEN";
//If value is 13
if(getValue()==13)
//Return
return "KING";
//Else
else
//Return
return "";
}
public int getSuit()
{
return suit;
}
public int getValue()
{
return value;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
