Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help converting this to linked list instead of using an array and the drive

ID: 3685987 • Letter: N

Question

Need help converting this to linked list instead of using an array and the driver class

public class Card
{

/********* Instance Data **************/

private String stringFaceValue; //string face of the card
private String stringSuitValue; //string suit of the card
private int numFaceValue; //integer face of the card
   //ace is 1 and Jack-King is 11-13
private int numSuitValue; //integer suit of the card
private int uniqueID; //a unique ID of each card

/********** Contructors **************/

public Card(int inSuit, int inFaceVal)
{
numFaceValue = inFaceVal;
numSuitValue = inSuit;
stringFaceValue = "";
uniqueID = 0;

if(inSuit == 1)
stringSuitValue = "Hearts";
else if(inSuit == 2)
stringSuitValue = "Clubs";
else if(inSuit == 3)
stringSuitValue = "Diamonds";
else
stringSuitValue = "Spades";
}

/************ Methods ***************/
public String toString()
{
//local constants

//local variables
String format; //formatted string to be returned

/********** begin toSTring ***************/

//check which face value to return
switch(numFaceValue)
{
case 1:
stringFaceValue = "Ace";
break;

case 2:
stringFaceValue = "Two";
   break;

case 3:
stringFaceValue = "Three";
break;

case 4:
stringFaceValue = "Four";
break;

case 5:
stringFaceValue = "Five";
break;

case 6:
stringFaceValue = "Six";
break;

case 7:
stringFaceValue = "Seven";
break;

case 8:
stringFaceValue = "Eight";
break;

case 9:
stringFaceValue = "Nine";
break;

case 10:
   stringFaceValue = "Ten";
   break;

case 11:
   stringFaceValue = "Jack";
   break;

case 12:
   stringFaceValue = "Queen";
   break;

case 13:
   stringFaceValue = "King";
   break;
}//end switch

//format the string
format = stringFaceValue + " of " + stringSuitValue;

//return the string
return format;
}

public int getNumber()
{
return numFaceValue;
}



} // end class Card'

---------------------------------------------

import java.lang.*;
import java.text.*;
import java.util.*;

public class DeckofCards
{

private static Card[] cards;//the array of cards
private static int numCards;//the number of cards in the deck

public DeckofCards(boolean shuffle)
{
numCards = 52;
cards = new Card[numCards];

int cardIndex = 0;

//for each suit of cards
for(int suit = 0; suit < 4; suit++)
{
for(int faceVal = 1; faceVal <= 13; faceVal ++)
{
//add a new card to deck
cards[cardIndex] = new Card(suit, faceVal);
cardIndex++;
}
}

//if the user wants to shuff
if(shuffle == true)
{
DeckofCards.shuffle();
}
}//end constructor

public static void shuffle()
{
//initialize random number generator
Random shuffleDeck = new Random();

//temporary card value
Card temp;

int tempIndex;

for(int i = 0; i < numCards; i++)
{
//get a random card to swap
tempIndex = shuffleDeck.nextInt(numCards);

//swap the cards
temp = cards[i];
cards[i] = cards[tempIndex];
cards[tempIndex] = temp;
}
}//end shuffle

public Card dealNextCard()
{
//get the top card
Card top = cards[0];

for(int c = 1; c < numCards; c++)
{
cards[c - 1] = cards[c];
}
cards[numCards - 1] = null;
numCards--;
return top;
}//end dealNextCard

public void printDeck()
{
for(int c = 0; c < numCards; c++)
{
System.out.println(cards[c]);
}
}//end printDeck
}

------------------------

import java.lang.*;
import java.text.*;
import java.util.*;

public class DeckofCards
{

private static Card[] cards;//the array of cards
private static int numCards;//the number of cards in the deck

public DeckofCards(boolean shuffle)
{
numCards = 52;
cards = new Card[numCards];

int cardIndex = 0;

//for each suit of cards
for(int suit = 0; suit < 4; suit++)
{
for(int faceVal = 1; faceVal <= 13; faceVal ++)
{
//add a new card to deck
cards[cardIndex] = new Card(suit, faceVal);
cardIndex++;
}
}

//if the user wants to shuff
if(shuffle == true)
{
DeckofCards.shuffle();
}
}//end constructor

public static void shuffle()
{
//initialize random number generator
Random shuffleDeck = new Random();

//temporary card value
Card temp;

int tempIndex;

for(int i = 0; i < numCards; i++)
{
//get a random card to swap
tempIndex = shuffleDeck.nextInt(numCards);

//swap the cards
temp = cards[i];
cards[i] = cards[tempIndex];
cards[tempIndex] = temp;
}
}//end shuffle

public Card dealNextCard()
{
//get the top card
Card top = cards[0];

for(int c = 1; c < numCards; c++)
{
cards[c - 1] = cards[c];
}
cards[numCards - 1] = null;
numCards--;
return top;
}//end dealNextCard

public void printDeck()
{
for(int c = 0; c < numCards; c++)
{
System.out.println(cards[c]);
}
}//end printDeck
}

1. Define a Class Card that will store the face value of the Card and the Suit Value 1. Include a minimun of 5 fields: o Face Value as Integer o Face Value as String o Suit Value as Integer o Suit Value as String o Card number of 1 to 52 (or 0 to 51) 2. Include a method to return the value of both for printing. I suggest you use toString). 2. Create a class for the Deck of Cards containing a set of operations that do the following: 1. Initializes a Linked List that contains all 52 cards in order. 2. Draws one card at a time from the Deck and removes the card from the deck. 3. Checks to see if there are any cards in the deck. 4. Keeps track of how many cards are left in the deck 5. Shuffles the deck 6. Print the deck for debugging purposes as vou test vour game. 3. Create a class for a dealt hand of cards containing a set of operations that do the following: 1. Initializes an empty hand of cards. 2. Prints the hand of cards. 3. Keeps track of how many cards are in the hand 4. Draws a card from the deck and places it in the hand 5. Removes the card from the hand randomly. 6. Removes the card from the hand by position 4. Create a Driver program that tests each of the methods for the deck and for the hand. Get one component working before moving on to the next 1. Print out the deck of cards 2. Print outthe dealt hand. 3. Prints out how many cards are in the deck 4. Prints out how many cards are in the hand. 5. Removes a card from the deck and places it in the hand a. Don't let a card be removed if the deck is empty a. Don't let a card be removed if the hand is empty. a. Don't let a card be removed if the hand is empty. 5. You must use Referenced-based Linked Lists for this progranm 6. Removes a card from the hand by position. f. Removes a card from the hand randomly. 6. You cannot use any built-in Java methods to manipulate your Linked Lists - you must write your own Linked List operations

Explanation / Answer

Please find the Linked List implementation below :

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote