Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Linked List Below public class Node { /********* Instance Data **************/ private String item1; //Data field 1 private String item2; //Data field 2 private

Using Linked List Below

image text in transcribed

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; /ode currently being processed Node prev; /ode previously processed //Fields of the node String firstName; //Student's first name String lastName; //Student's last name Node next; /ext 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(); } /ame not found if (current.getNext() == null && lastN.compareToIgnoreCase(current.getLast()) != 0) { System.out.println("Name not found"); } /ame found at end of list else if ((current.getNext() == null && lastN.compareToIgnoreCase(current.getLast()) == 0)) { prev.setNext (null); } /ame 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); /ew 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())

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

Explain the various methods of job evaluation

Answered: 1 week ago

Question

Differentiate Personnel Management and Human Resource Management

Answered: 1 week ago

Question

Describe the functions of Human resource management

Answered: 1 week ago