Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My Program does not print anything out. Can someone lead in the right direction public class LinkedList { private Node first = null; private Node

My Program does not print anything out. Can someone lead in the right direction

image text in transcribedimage text in transcribed

public class LinkedList {

private Node first = null;

private Node current = null;

private Node pre = null;

public boolean isEmpty(){

return true;

}

public boolean contains(Comparable item){

current = first;

pre = null;

while ((current != null)&&(current.getData().compareTo(item)

pre = current;

current = current.getNext();

}

return ((current != null) && (current.getData().compareTo(item) == 0));

}

public int size(){

int count = 0;

current = first;

pre = null;

while (current != null){

pre = current;

current = current.getNext();

count++;

}

return count;

}

public void add(Comparable c){

Node temp = new Node(c);

if (pre == null){

first = temp;

}else{

pre.setNext(temp);

}

temp.setNext(current);

current = temp;

}

public void remove(Comparable c){

if (pre == null){

first = first.getNext();

}else{

current = current.getNext();

if (pre == null){

first = current;

}else{

pre.setNext(current);

}

}

}

public void clear(){

first = null;

}

public void print(){

Node current = first;

while (current != null){

System.out.println(current.getData());

current = current.getNext();

}

}

}

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

public class Node {

private Comparable data;

private Node next;

public Node(){

next = null;

}

public Node(Comparable c){

data = c;

next = null;

}

public Node(Comparable c, Node n){

data = c;

next = n;

}

public Comparable getData(){

return data;

}

public void setData(Comparable c){

data = c;

}

public Node getNext(){

return next;

}

public void setNext(Node n){

next = n;

}

}

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

public class Card implements Comparable {

private int rank;

private int suit;

public Card(int suit, int rank){

this.rank = rank;

this.suit = suit;

}

public int getRank(){

return rank;

}

public int getSuit(){

return suit;

}

public String toString(){

switch(suit){

case 1:

switch(rank)

{

case 11: return "Jack of Hearts";

case 12: return "Queen of Hearts";

case 13: return "King of Hearts";

case 14: return "Ace of Hearts";

default: return rank + " of Hearts";

}

case 2:

switch(rank)

{

case 11: return "Jack of Diamonds";

case 12: return "Queen of Diamonds";

case 13: return "King of Diamonds";

case 14: return "Ace of Diamonds";

default: return rank + " of Diamonds";

}

case 3:

switch(rank)

{

case 11: return "Jack of Clubs";

case 12: return "Queen of Clubs";

case 13: return "King of Clubs";

case 14: return "Ace of Clubs";

default: return rank + " of Clubs";

}

case 4:

switch(rank)

{

case 11: return "Jack of Spades";

case 12: return "Queen of Spades";

case 13: return "King of Spades";

case 14: return "Ace of Spades";

default: return rank + " of Spades";

}

}//end Switch Statement

return null;

}

public int compareTo(Card a) {

if (this.rank

return -1;

}

if (this.rank > a.rank){

return 1;

}

if (this.rank == a.rank){

if (this.suit

return -1;

}

if (this.suit > a.suit){

return 1;

}

}

return 0;

}

}

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

import java.util.Random;

public class CardDeck {

private LinkedList cards=new LinkedList();

private int numCards;

public void Deck(){

for (int a = 1; a

for (int b = 1; b

cards.add(new Card(a,b));

}

}

}

public void drawFromDeck(){

Random rand = new Random();

int index = rand.nextInt(cards.size());

cards.remove(index);

setNumCards(getNumCards() - 1);

}

public int getTotalCard(){

return cards.size();

}

public int getNumCards() {

return numCards;

}

public void setNumCards(int numCards) {

this.numCards = numCards;

}

}

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

package classWork;

public class Main

{

public static void main(String[] args)

{

LinkedList myList = new LinkedList();

CardDeck myCards = new CardDeck();

myCards.Deck();

myList.print();

}

}

Using Linked Lists, design a Deck of Cards with the following criteria: 1. Define a Class Card that will store the face value of the Card and the Suit Value 1. Include five fields: - Numeric Face Value - for processing purposes - String Face Value - for printing purposes - Numeric Suit Value - for processing purposes - String Suit Value - for printing purposes Unique ID Card number of 1 to 52 (or 0 to 51) Next field to link to the next card. 2. Have the constructor initialize the next field to null. No data will be set within the constructor. 3. Include a set and a get method for each of the following: - String Face Value. * String Suit Value. - Numeric Face Value. Numeric Suit Value. ID number of card Next field of card (pointer to the next card in deck) - - 2. Create a class for the Deck of Cards containing a set of operations that do the following: 1. Include the following fields: Head node - points to the first card in the deck. First node - a temporary pointer that points to the first card in the deck. Current node - a node that points to the current card when traveling through the deck of cards (the linked list) Previous node - a node that points to the previous card visited when traveling through the deck of cards (linked list)

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions

Question

5. If yes, then why?

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago