Question: TileNode.Java public class TileNode{ // instance variables private int data; private TileNode link; public TileNode() {} // constructor public TileNode(int initialData, TileNode initialLink) { data

 TileNode.Java public class TileNode{ // instance variables private int data; private

TileNode.Java

public class TileNode{

// instance variables private int data; private TileNode link; public TileNode() {} // constructor public TileNode(int initialData, TileNode initialLink) { data = initialData; link = initialLink; } // the calling object is a reference to the // node before the location where I want to add public void addNodeAfter(int item){ link = new TileNode(item, link); } public int getData( ) { return data; } public TileNode getLink( ){ return link; } public static TileNode[ ] split ( TileNode original, int sValue ) { TileNode cursor = original; TileNode answer[ ] = new TileNode [ 2 ]; TileNode list1=null, list1cursor=null; TileNode list2=null, list2cursor=null; while ( cursor != null ) { if ( cursor.getData() = splitValue } // end while answer[0] = list1; answer [1] = list2; return answer; }// end method public static String listToString( TileNode head ) { String answer = ""; TileNode cursor = head; while (cursor != null) { answer = answer + cursor.getData(); if (cursor.getLink() == null) answer = answer + " End of List"; else answer = answer + " --> "; cursor = cursor.getLink(); } return answer; } // call this method using IntNode.listCopy(reference to the head) // it will duplicate the list and return a reference which // is the head of the new list public static TileNode listCopy(TileNode source){ TileNode copyHead; TileNode copyTail; // Handle the special case of the empty list. if (source == null) return null; // Make the first node for the newly created list. copyHead = new TileNode(source.data, null); copyTail = copyHead; // Make the rest of the nodes for the newly created list. while (source.link != null){ source = source.link; copyTail.addNodeAfter(source.data); copyTail = copyTail.link; } // Return the head reference for the new list. return copyHead; } public static int listLength(TileNode head){ int answer = 0; for (TileNode cursor = head; cursor != null; cursor = cursor.link) answer++; return answer; } // search for a particular data value in the list // return a reference to the node where the value // was found // if the value isn't in the list, return null public static TileNode listSearch(TileNode head, int target){ TileNode cursor; for (cursor = head; cursor != null; cursor = cursor.link) if (target == cursor.data) return cursor; return null; } // this method is called using the node // that is before the one we want to remove public void removeNodeAfter( ){ link = link.link; } // mutator public void setData(int newData){ data = newData; } public void setLink(TileNode newLink){ link = newLink; } //added portion for the lab //wont compile public static void printList(TileNode head){ if(head == null) return; TileNode node = head; while(true) { System.out.println(node.data); if(node.link != null) node=node.link; else break; } } public static TileNode insertAtHead(TileNode head, TileNode tile){ TileNode node = new TileNode(); node.data = tile.data; node.link = head; return node; } public static TileNode reverse(TileNode original){ TileNode prev = null; TileNode cur = original; TileNode link = null; while(cur != null) { link = cur.link; cur.link = prev; prev = cur; cur = link; } original = prev; return original; } }

B: Create a test program called QwirkleHandTest.java. Write a main method. Inside the main method, start with the statements TileNode qwirkleHand = null; EmmBag game 1 = new QwirkleBag( ); // draw 6 tiles out of the bag and add them to the player's hand qwirkleHand TileNode.insertAtHead( qwirkleHand, new TileNode (game1.draw nu1l) // display the tiles in the player's hand TileNode.printList( qwirkleHand Compile, debug, run. Repeat until these statements work correctly .Add statements to the main so that it will test the other methods in the TileNode class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!