Question: Java Program : I need help implementing my own linked list instead of using an array to work with these classes. Please help !! public

Java Program : I need help implementing my own linked list instead of using an array to work with these classes. Please help !!

Java Program : I need help implementing my own linked list instead

public class Card { public final static int SPADES = 0, // Codes for the 4 suits. HEARTS = 1, DIAMONDS = 2, CLUBS = 3; public final static int ACE = 1, // Codes for the non-numeric cards. JACK = 11, // Cards 2 through 10 have their QUEEN = 12, // numerical values for their codes. KING = 13; private final int suit; // The suit of this card, one of the constants // SPADES, HEARTS, DIAMONDS, CLUBS. private final int value; // The value of this card, from 1 to 11. public Card(int theValue, int theSuit) { // Construct a card with the specified value and suit. // Value must be between 1 and 13. Suit must be between // 0 and 3. If the parameters are outside these ranges, // the constructed card object will be invalid. value = theValue; suit = theSuit; } public int getSuit() { // Return the int that codes for this card's suit. return suit; } public int getValue() { // Return the int that codes for this card's value. return value; } public String getSuitAsString() { // Return a String representing the card's suit. // (If the card's suit is invalid, "??" is returned.) switch ( suit ) { case SPADES: return "Spades"; case HEARTS: return "Hearts"; case DIAMONDS: return "Diamonds"; case CLUBS: return "Clubs"; default: return "??"; } } public String getValueAsString() { // Return a String representing the card's value. // If the card's value is invalid, "??" is returned. switch ( value ) { case 1: return "Ace"; case 2: return "2"; case 3: return "3"; case 4: return "4"; case 5: return "5"; case 6: return "6"; case 7: return "7"; case 8: return "8"; case 9: return "9"; case 10: return "10"; case 11: return "Jack"; case 12: return "Queen"; case 13: return "King"; default: return "??"; } } public String toString() { // Return a String representation of this card, such as // "10 of Hearts" or "Queen of Spades". return getValueAsString() + " of " + getSuitAsString(); } } // end class Card

Deck Class :

public class Card { public final static int SPADES = 0, // Codes for the 4 suits. HEARTS = 1, DIAMONDS = 2, CLUBS = 3; public final static int ACE = 1, // Codes for the non-numeric cards. JACK = 11, // Cards 2 through 10 have their QUEEN = 12, // numerical values for their codes. KING = 13; private final int suit; // The suit of this card, one of the constants // SPADES, HEARTS, DIAMONDS, CLUBS. private final int value; // The value of this card, from 1 to 11. public Card(int theValue, int theSuit) { // Construct a card with the specified value and suit. // Value must be between 1 and 13. Suit must be between // 0 and 3. If the parameters are outside these ranges, // the constructed card object will be invalid. value = theValue; suit = theSuit; } public int getSuit() { // Return the int that codes for this card's suit. return suit; } public int getValue() { // Return the int that codes for this card's value. return value; } public String getSuitAsString() { // Return a String representing the card's suit. // (If the card's suit is invalid, "??" is returned.) switch ( suit ) { case SPADES: return "Spades"; case HEARTS: return "Hearts"; case DIAMONDS: return "Diamonds"; case CLUBS: return "Clubs"; default: return "??"; } } public String getValueAsString() { // Return a String representing the card's value. // If the card's value is invalid, "??" is returned. switch ( value ) { case 1: return "Ace"; case 2: return "2"; case 3: return "3"; case 4: return "4"; case 5: return "5"; case 6: return "6"; case 7: return "7"; case 8: return "8"; case 9: return "9"; case 10: return "10"; case 11: return "Jack"; case 12: return "Queen"; case 13: return "King"; default: return "??"; } } public String toString() { // Return a String representation of this card, such as // "10 of Hearts" or "Queen of Spades". return getValueAsString() + " of " + getSuitAsString(); } } // end class Card

Hand Class :

public class Card { public final static int SPADES = 0, // Codes for the 4 suits. HEARTS = 1, DIAMONDS = 2, CLUBS = 3; public final static int ACE = 1, // Codes for the non-numeric cards. JACK = 11, // Cards 2 through 10 have their QUEEN = 12, // numerical values for their codes. KING = 13; private final int suit; // The suit of this card, one of the constants // SPADES, HEARTS, DIAMONDS, CLUBS. private final int value; // The value of this card, from 1 to 11. public Card(int theValue, int theSuit) { // Construct a card with the specified value and suit. // Value must be between 1 and 13. Suit must be between // 0 and 3. If the parameters are outside these ranges, // the constructed card object will be invalid. value = theValue; suit = theSuit; } public int getSuit() { // Return the int that codes for this card's suit. return suit; } public int getValue() { // Return the int that codes for this card's value. return value; } public String getSuitAsString() { // Return a String representing the card's suit. // (If the card's suit is invalid, "??" is returned.) switch ( suit ) { case SPADES: return "Spades"; case HEARTS: return "Hearts"; case DIAMONDS: return "Diamonds"; case CLUBS: return "Clubs"; default: return "??"; } } public String getValueAsString() { // Return a String representing the card's value. // If the card's value is invalid, "??" is returned. switch ( value ) { case 1: return "Ace"; case 2: return "2"; case 3: return "3"; case 4: return "4"; case 5: return "5"; case 6: return "6"; case 7: return "7"; case 8: return "8"; case 9: return "9"; case 10: return "10"; case 11: return "Jack"; case 12: return "Queen"; case 13: return "King"; default: return "??"; } } public String toString() { // Return a String representation of this card, such as // "10 of Hearts" or "Queen of Spades". return getValueAsString() + " of " + getSuitAsString(); } } // end class Card

public interface List { /** * Adds the object x to the end of the list. * @param x the element to be added to this list * @return true */ public boolean add(Card x); /** * Adds the object x at the specified position * @param index the position to add the element * @param x the element to be added to the list * @return true if the operation succeeded, false otherwise * @throws IllegalArgumentException if index is invalid */ public boolean add(int index, Card x); /** * Returns the number of elements in this list * @return the number of elements in this list */ public int size(); /** * Returns the element with the specified position in this list * @param index the position of the element * @return the element at the specified position in this list * @throws IllegalArgumentException if index is invalid */ public Card get(int index); /** * Replaces the object at the specified position * @param index the position to replace * @param x the element to be stored * @return the previous value of the element at index * @throws IllegalArgumentException if index is invalid */ public Card set(int index, Card x); /** * Removes the object at the specified position * @param index the position to remove * @return the object that was removed * @throws IllegalArgumentException if index is invalid */ public Card remove(int index); /** * Tests if this list has no elements. * @return true if this list has no elements; * false otherwise. */ public boolean isEmpty(); /** * Returns true if this list contains the specified element. * * @param element element whose presence in this List is to be tested. * @return true if the specified element is present; * false otherwise. */ public boolean contains(Card element); /** * Returns the index of the specified element * * @param element the element we're looking for * @return the index of the element in the list, or -1 if it is not contained within the list */ public int indexOf(Card element); } 
public class LinkedList implements List { // TODO: put class fields here // inner node class class Node { // TODO: put class fields here // TODO: put class constructors and methods here } // TODO: add constructors here /** * Adds the object x to the end of the list. * @param x the element to be added to this list * @return true */ public boolean add(Card x) { return false; // TODO: replace with working code } /** * Adds the object x at the specified position * @param index the position to add the element * @param x the element to be added to the list * @return true if the operation succeeded, false otherwise * @throws IllegalArgumentException if index is invalid */ public boolean add(int index, Card x) { return false; // TODO: replace with working code } /** * Returns the number of elements in this list * @return the number of elements in this list */ public int size() { return 0; // TODO: replace with working code } /** * Returns the element with the specified position in this list * @param index the position of the element * @return the element at the specified position in this list * @throws IllegalArgumentException if index is invalid */ public Card get(int index) { return null; // TODO: replace with working code } /** * Replaces the object at the specified position * @param index the position to replace * @param x the element to be stored * @return the previous value of the element at index * @throws IllegalArgumentException if index is invalid */ public Card set(int index, Card x) { return null; // TODO: replace with working code } /** * Removes the object at the specified position * @param index the position to remove * @return the object that was removed * @throws IllegalArgumentException if index is invalid */ public Card remove(int index) { return null; // TODO: replace with working code } /** * Tests if this list has no elements. * @return true if this list has no elements; * false otherwise. */ public boolean isEmpty() { return false; // TODO: replace with working code } /** * Returns true if this list contains the specified element. * * @param element element whose presence in this List is to be tested. * @return true if the specified element is present; * false otherwise. */ public boolean contains(Card element) { return false; // TODO: replace with working code } /** * Returns the index of the specified element * * @param element the element we're looking for * @return the index of the element in the list, or -1 if it is not contained within the list */ public int indexOf(Card element) { return 0; // TODO: replace with working code } public static void main(String[] args) { // TODO: insert main code here } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!