Well I'm trying to use a Linked list and i have a Card class and a Node class. In my deck class I want my default constructor to create a deck full of 52 cards. this is what i have so far:In my main class I have this code :package project3; import java.util.LinkedList; public class Deck { private Node front; private int remainingCards = 52; LinkedList myDeck; public Deck() { for(int i = 0; i < 52; i++) { Node temp = front; if(front == null) { front = new Node(new Card(i), null); } else { temp.setNext(new Node(new Card(i), null)); temp.getNext(); } } } public String toString() { String output = new String("Cards \n"); Node traveller = front; while(traveller.getNext() != null) { output += traveller.getItem() + "\n"; traveller = traveller.getNext(); } return output; } }which only outputs:Deck xDeck = new Deck(); System.out.println(xDeck.toString());Why isnt the rest of the deck not printing? Or is the deck not being created properly?Cards
King of clubs
For reference this is my Card class:
and this is my Node class:package project3; /** * <p>Title: The Card class</p> * * <p>Description: This class will represent a single playing card * that has a value between 1 and 13 and a suit (Clubs, Diamonds, * Hearts or Spades). A card can return its value, suit, point value * or reference to a String containing the card’s value and suit. It * can check to see if two cards have the same value or the same suit.</p> * * @author CSC 120 Instructor */ public class Card { // instance variables private int value; private String suit; /** * parameterized Card constructor -- * gets called when an object of the Card class is instantiated * sending a number as an argument -- it determines the value and * suit of the card based upon the number received * @param num a number that gets converted to a value between 1 and * 13 and a suit */ public Card(int num) { int suitNumber; value = num % 13; if (value == 0) value = 13; suitNumber = num / 13; if (suitNumber == 0) suit = "clubs"; else if (suitNumber == 1) suit = "diamonds"; else if (suitNumber == 2) suit = "hearts"; else if (suitNumber == 3) suit = "spades"; else suit = "ERROR"; } /** * getValue method -- * returns what's stored in the instance variable value * @return the state of the instance variable value */ public int getValue() { return value; } /** * getSuit method -- * returns what's stored in the instance variable suit * @return a reference to a String that contains the state of the * instance variable suit */ public String getSuit() { return suit; } /** equalValue method -- * determines if the otherCard's value is the same as this card's value * @param otherCard a reference to the Card object (assumes the object * has been instantiated) to compare to this Card object * @return true if the values are equal, false if the values are not equal */ public boolean equalValue(Card otherCard) { if (this.value == otherCard.value) return true; else return false; } /** * equalSuit method -- * determines if the otherCards's suit is the same as this card's suit * @param otherCard a reference to the Card object (assumes the object * has been instantiated) to compare to this Card object * @return true if the suits are the same, false if they are not */ public boolean equalSuit(Card otherCard) { if (this.suit.equals(otherCard.suit)) return true; else return false; } /** * toString method -- * returns the state of the card object * @return a reference to a String object that contains the value * and suit of the card */ public String toString() { if (value == 1) return "Ace of " + suit; else if (value == 11) return "Jack of " + suit; else if (value == 12) return "Queen of " + suit; else if (value == 13) return "King of " + suit; else return value + " of " + suit; } }package project3; /** * <p>Title: Node Class</p> * * <p>Description: Defines a node class capable of storing a * reference to an object and a reference to the next node in * a linked list. Accessors and mutators are defined for both.</p> * * @author Darci Burdge */ public class Node { private Card data; //a reference to an object of type T private Node next; //the address of the next node in the list /** * default constructor - initializes data and next to null */ public Node() { data = null; next = null; } /** * parameterized constructor - initializes data to the user * specified value; next is set to null * @param newItem the value to be stored in the node */ public Node(Card newItem) { data = newItem; next = null; } /** * parameterized constructor - initializes data and next to user * specified values * @param newItem the object reference to be stored in the node * @param nextItem the reference to the next node in the list */ public Node(Card newItem, Node nextItem) { data = newItem; next = nextItem; } /** * setItem - stores a new value in data * @param newItem the object reference to be stored in the node */ public void setItem(Card newItem) { data = newItem; } /** * setNext - stores a new value in next * @param nextItem the reference to be stored in next */ public void setNext(Node nextItem) { next = nextItem; } /** * getItem - returns the reference stored in data * @return a reference to the data stored in the node */ public Card getItem() { return data; } /** * getNext - returns the reference stored in next * @return the reference stored in next */ public Node getNext() { return next; } }