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

Using Linked List Below public class Node { /********* Instance Data ***********

ID: 3697196 • Letter: U

Question

Using Linked List Below

public class Node
{

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

private String item1; //Data field 1
private String item2; //Data field 2
private Node next; //Link to next node

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

public Node()
//New empty node - no data, points to NULL
   {
next = null;
   }
public Node(String newItem1, String newItem2)
// New node with data that points to NULL
   {
item1 = newItem1;
item2 = newItem2;
next = null;
   } // end constructor

public Node(String newItem1, String newItem2, Node nextNode)
// New node with data that links to Next Node
   {
item1 = newItem1;
item2 = newItem2;
next = nextNode;
   } // end constructor

/************ Methods ***************/

//Method to set the value of the instance variable from Class ListInfo.
//Postcondition: instance variable = x;
public void setString(String newItem1, String newItem2)
{
item1 = newItem1;
item2 = newItem2;
}

//Method to return the value of the instance variable from Class ListInfo.
//Postcondition: The value of item is returned.
public String getFirst()
{
return item1;
}

//Method to return the value of the instance variable from Class ListInfo.
   //Postcondition: The value of item is returned.
   public String getLast()
   {
   return item2;
}

   public void setNext(Node changeNext)
   {
next = changeNext;
   }

   public Node getNext()
   {
return next;
   }


} // end class Node

public class ListNodes
{
   //Instance data

   //Nodes I use to traverse the list
Node head; //points to first node
Node first; //temp position for first node
Node current; //node currently being processed
Node prev; //node previously processed

//Fields of the node
String firstName; //Student's first name
   String lastName; //Student's last name
   Node next; //next node in list




   public ListNodes()
   {

head = null; //empty list
   }

   public void printString( ) //print out the list
   {
first = head; //store head of list
System.out.println(" ");
for (current = first; current != null; current = current.getNext())
System.out.println(current.getFirst() + " " + current.getLast());
System.out.println(" ");
   }

   public void deleteNode (String lastN)
{
first = head;
   current = first;

if (first != null) //list has nodes
{
   //check first node
   if (lastN.compareToIgnoreCase(first.getLast()) == 0)
   {
first = first.getNext();
   }
   else //check rest of list
   {

while(current.getNext() != null && lastN.compareToIgnoreCase(current.getLast()) != 0)
{
   prev = current;
   current = current.getNext();
}

//name not found
if (current.getNext() == null && lastN.compareToIgnoreCase(current.getLast()) != 0)
{
   System.out.println("Name not found");
}
//name found at end of list
else if ((current.getNext() == null && lastN.compareToIgnoreCase(current.getLast()) == 0))
{
   prev.setNext (null);
}
//name found within list
else //if ( (lastN.compareToIgnoreCase(current.getLast())) = 0 )
{
   prev.setNext (current.getNext());
   current.setNext (null);
}
   }//end else
}//end if first
head = first; //update head to new first of list
   }//end delete

   public void insert (String firstN, String lastN)
{
   first = head; //store head of list

   Node newData = new Node (lastN, firstN); //place data in new node


   if (first == null) //if list is empty
   {
first = newData; //first points to new node
   }
   else //list is not empty
   {
//does new data come first
if (first.getLast().compareToIgnoreCase(newData.getLast()) > 0)
{

   //insert new data at front of list and return as head
   newData.setNext(first); //new node points to first node
   first = newData; //head now points to new node

}// end current.getLast
else //insert in list
{
   prev = first;
   current = first.getNext();
   while (current != null &&
current.getLast().compareToIgnoreCase(newData.getLast()) < 0) //Stop at position
   {
prev = current;
current = current.getNext();
   }//end while current

   //if new data goes at end of list
   if (current == null)
prev.setNext(newData);

   else //new data goes in the middle of the list
   {
newData.setNext(current);
   prev.setNext(newData);
   }//end else middle of list
}//end else insert in list
   }//end else not empty list

   head = first; //update head of list

}//end insert


}//end class

Card Game using Linked Lists Using Linked Lists, design a Deck of Cards and a hand dealt from the Deck with the following criteria: 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 returns the face and suit value of the card drawn. When a card is drawn from the deck, it will also remove the card drawn 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. Print an ordered deck for debugging purposes as you test this class. 6. Shuffle. 7. Print the shuffled deck for debugging purposes as you test your 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. Allows the player to look at the contents of the hand. 4. Keeps track of how many cards are in the hand. 5. Draws a card from the deck and places it in the hand. You may decide to draw the card in the Deck of Cards class or in the Driver. If you do then you will simply send this method the card drawn elsewhere and use this method to insert it in the hand. 6. Removes the card from the hand both randomly and by position. 4. Create a Driver program that plays a card game between the computer and a player. Divide the deck between two players: you and the computer. This means that each "hand" will be half the deck. You pick a card from your hand and the computer picks a card from it's own hand. Display both. The higher value on the card wins. Aces are the highest card A point is awarded to whoever has the highest card. If both cards are the same, then each player draws another card until there is a winner. o The game ends when the last two cards are drawn. ° The player with the highest points wins. o Prompt to play another game - and initialize everything back to a starting state. 5. You must use Referenced-based Linked Lists for this program as introduced in the Linked List Module.

Explanation / Answer

Answer 1

public class Card {
   public int faceValue;
   public String faceValue1;
   public int SuitValue;
   public String SuitValue1;
   public int CardNumber;
   public Card(int faceValue, String faceValue1, int suitValue,
           String suitValue1, int cardNumber) {
       super();
       this.faceValue = faceValue;
       this.faceValue1 = faceValue1;
       SuitValue = suitValue;
       SuitValue1 = suitValue1;
       CardNumber = cardNumber;
   }
   public Card(Comparable c) {
       // TODO Auto-generated constructor stub
   }
   public int getFaceValue() {
       return faceValue;
   }
   public void setFaceValue(int faceValue) {
       this.faceValue = faceValue;
   }
   public String getFaceValue1() {
       return faceValue1;
   }
   public void setFaceValue1(String faceValue1) {
       this.faceValue1 = faceValue1;
   }
   public int getSuitValue() {
       return SuitValue;
   }
   public void setSuitValue(int suitValue) {
       SuitValue = suitValue;
   }
   public String getSuitValue1() {
       return SuitValue1;
   }
   public void setSuitValue1(String suitValue1) {
       SuitValue1 = suitValue1;
   }
   public int getCardNumber() {
       return CardNumber;
   }
   public void setCardNumber(int cardNumber) {
       CardNumber = cardNumber;
   }
   @Override
   public String toString() {
       return "Card [faceValue=" + faceValue + ", faceValue1=" + faceValue1
               + ", SuitValue=" + SuitValue + ", SuitValue1=" + SuitValue1
               + ", CardNumber=" + CardNumber + ", getFaceValue()="
               + getFaceValue() + ", getFaceValue1()=" + getFaceValue1()
               + ", getSuitValue()=" + getSuitValue() + ", getSuitValue1()="
               + getSuitValue1() + ", getCardNumber()=" + getCardNumber()
               + "]";
   }
   public Comparable getData() {
       // TODO Auto-generated method stub
       return null;
   }
   public Card getNext() {
       // TODO Auto-generated method stub
       return null;
   }
   public void setNext(Card temp) {
       // TODO Auto-generated method stub
      
   }
  
  
}


Answer 2:


public class LinkedListForDeckOfCards {
   private Card first = null;
   private Card current = null;
    private Card previous = null;
  
    public boolean isEmpty(){
     return true;
}
public boolean contains(Comparable item){
                current = first;
                previous = null;
                while ((current != null)&&(current.getData().compareTo(item) < 0)){
                    previous = current;
                    current = current.getNext();
                    }
                return ((current != null) && (current.getData().compareTo(item) == 0));
            }
          
            public int size(){
                int count = 0;
                current = first;
                previous = null;
   while (current != null){
                    previous = current;
                    current = current.getNext();
                    count++;
            }
            return count;
    }
  
        public void add(Comparable c){
    Card temp = new Card(c);
if (previous == null){
first = temp;
                }else{
  
                previous.setNext(temp); }
   temp.setNext(current);
current = temp;
  
            }
   public void removecard(Comparable c){
   if (previous == null){
                    first = first.getNext();
   }else{
current = current.getNext();
if (previous == null){
first = current;
}else{
      previous.setNext(current);
   }
    }
}
public void clearCard(){
                first = null;
   }
   public void print(){
Card current = first;
while (current != null){
System.out.println(current.getData());
current = current.getNext();
}
            }

       }

Approach 2

import java.awt.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;


public class DeckOfCardss {
   static void cardList(int numHands,int cardsPerHand){
        List<String> deck,hand;

Srting[] suit=new String[]{"S","H","D","C"};
       String[] rank=new String[]{"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
       deck=new ArrayList<String>();
       for(int i=0;i<deck.length;i++){
          for(int j=i;j<deck.length;j++){
              deck.add(rank[i]+"-"+suit[j]);
     public void drawFromDeck(){
      
                    Random rand = new Random();
      
                    List cards;
                   int index = rand.nextInt();
      
                    cards.remove(index);
      
                    int numCards;
                   numCards--;
    Object deck;
   Collections.shuffle((java.util.List<?>) deck);

             int numHands;
for(int i=0;i<numHands;i++){
                      int cardsPerHand;
                   Object hand = deck.subList(deck.size()-cardsPerHand,deck.size());
                      System.out.println(hand);
                    
}
}

}

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