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

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

ID: 3684433 • Letter: M

Question

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

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) < 0)){

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<Card> {

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 < a.rank){

return -1;

}

if (this.rank > a.rank){

return 1;

}

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

if (this.suit < a.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 <= 4; a++){

for (int b = 1; b <= 14; 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). - -

Explanation / Answer

Check whether the card class logic in the given program is similar to the card class logic given below.

If the logic is same Then try moving the toString() method from the card method to the CardDeck class.

public class Card {

  

   public final static int SPADES = 0;   // Codes for the 4 suits, plus Joker.

   public final static int HEARTS = 1;

   public final static int DIAMONDS = 2;

   public final static int CLUBS = 3;

   public final static int JOKER = 4;

  

   public final static int ACE = 1;      // Codes for the non-numeric cards.

   public final static int JACK = 11;    //   Cards 2 through 10 have their

   public final static int QUEEN = 12;   //   numerical values for their codes.

   public final static int KING = 13;

private final int suit;

private final int value;

public Card() {

      suit = JOKER;

      value = 1;

   }

public Card(int theValue, int theSuit) {

      if (theSuit != SPADES && theSuit != HEARTS && theSuit != DIAMONDS &&

            theSuit != CLUBS && theSuit != JOKER)

         throw new IllegalArgumentException("Illegal playing card suit");

      if (theSuit != JOKER && (theValue < 1 || theValue > 13))

         throw new IllegalArgumentException("Illegal playing card value");

      value = theValue;

      suit = theSuit;

   }

public int getSuit() {

      return suit;

   }

public int getValue() {

      return value;

   }

public String getSuitAsString() {

      switch ( suit ) {

      case SPADES:   return "Spades";

      case HEARTS:   return "Hearts";

      case DIAMONDS: return "Diamonds";

      case CLUBS:    return "Clubs";

      default:       return "Joker";

      }

   }

public String getValueAsString() {

      if (suit == JOKER)

         return "" + value;

      else {

         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";

         default: return "King";

         }

      }

   }

public String toString() {

      if (suit == JOKER) {

         if (value == 1)

            return "Joker";

         else

            return "Joker #" + value;

      }

      else

         return getValueAsString() + " of " + getSuitAsString();

   }

  

} // end class Card

note-the above explanation on code may help to solve the problem given.

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