Question: java language linked list assignment ------------------------------------------------------------------ //Game Entry Class for HW 4 //Define program public class GameEntry{ //Instance Variables private String name; private int score;

java language linked list assignment

java language linked list assignment ------------------------------------------------------------------ //Game Entry Class for HW 4

//Define program public class GameEntry{ //Instance Variables private String name; private int

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

//Game Entry Class for HW 4 //Define program public class GameEntry{ //Instance Variables private String name; private int score; //Constructor public GameEntry(String n, int s){ name=n; score=s; } //Getter methods public String getName(){return name;} public int getScore(){return score;} public String toString(){return "(" + name + "," + score + ")";} }

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

//Scoreboard class for Homework 4 //Define program class public class Scoreboard{ //Instance Variables private int numEntries =0; private GameEntry[] board; //Constructor //Making an Empty Scoreboard public Scoreboard(int capacity){ board = new GameEntry[capacity]; } //Method public void add(GameEntry e){ //Check to see if the score is high enough int newScore =e.getScore(); //This assumes our array is already sorted from highest to lowest if(numEntries  board[numEntries-1].getScore()){ if(numEntries 0 && board[j-1].getScore()=numEntries){ throw new IndexOutOfBoundsException("Invalid index: " + i); } GameEntry temp = board[i]; for(int j=i; j

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

//Code for the Singly Linked List Class public class SinglyLinkedList{ //Nested class private static class Node{ //Instane Varaibles private E element; private Node next; //Constructor public Node(E e, Node n){ element=e; next=n; } //Methods public E getElement(){return element;} public Node getNext(){return next;} public void setNext(Node n){next=n;} } //End Nested Node class //Instance Variables for the SLL class private Node head =null; private Node tail =null; private int size =0; //Constructor public SinglyLinkedList(){}//Just create empty SLL //Method for the Singly Linked List class //Access Methods public int getSize(){return size;} public boolean isEmpty(){return size==0;} //First method returns the element at the head of the list public E first(){ if(isEmpty()) {return null;} return head.getElement(); } //Last method: return the element at the tail of list public E last(){ if(isEmpty()){ return null;} return tail.getElement(); } //Update methods //addFirst Method: add new element as the head of the SLL public void addFirst(E e){ head = new Node(e, head); if(size==0){ tail=head; } size++; } //addLast Method: add new element as the tail of SLL public void addLast(E e){ Node newest = new Node(e, null); if(isEmpty()){ head=newest; } else{ tail.setNext(newest); } tail= newest; size++; } //removeFirst method: This return and remove the head element of the SLL public E removeFirst(){ if(isEmpty()){return null;} E answer = head.getElement(); head= head.getNext(); size--; if(size==0){ tail=null; } return answer; } }

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

I have to create two method in SinglyLinkedList class to print all the elements in singly-linked list and the summary of elements in there (average, range, and so on..).

Homework 5 Due February 23rd 11:00 AM 100 points CS 2235 Data Structures and Algorithms 1. Using the SinglyLinkedList class from the lectures (the code will be posted to Moodle), modify your code from Homework 4 to use a singly linked list rather than the Scoreboard class for problems 1,2 and 3. 2. Create a DoublyLinkedList class using the SinglyLinkedList class as a reference. Note*Hint* Pages 136-137 from the book contain much of the code and you are welcome to reference them; just make sure you understand it (these slides will be posted to Moodle for your reference). 3. Finally, modify your code from Homework 4 once again, this time using the DoublyLiked List. (Again, only parts 1-3) Make sure to submit Java files for your SinglyLinkedList, DoublyLinkedList, GameEntry and both Scoreboards. As always, attach screenshots to demonstrate your code works. Note: Sorting with Linked List can be challenging. We have yet to really discuss the nature of sorting algorithms, so for this assignment your Linked Lists do not have to be sorted. Homework 4 Due February 16th 11:00 AM 100 points CS 2235 Data Structures and Algorithms 1. Using the Scoreboard and GameEntry classes from the lecture (these will be posted to Moodle), create a Scoreboard that can contain up to 20 GameEntry objects. 2. Now, create 20 new GameEntry objects with a name (Player 1, Player 2, etc.) and a random score between 0 and 1000, and add them to your Scoreboard array using the add method. Hint: The easiest way to create your GameEntries is to use a loop. 3. Create a method inside the Scoreboard class that prints all the elements inside the array to the screen. Then create another method which displays a summary of the array. This method must include: the number of elements inside the scoreboard, the highest and lowest values, range of scores and the average value of the scoreboard. Demonstrate that both methods work. Homework 5 Due February 23rd 11:00 AM 100 points CS 2235 Data Structures and Algorithms 1. Using the SinglyLinkedList class from the lectures (the code will be posted to Moodle), modify your code from Homework 4 to use a singly linked list rather than the Scoreboard class for problems 1,2 and 3. 2. Create a DoublyLinkedList class using the SinglyLinkedList class as a reference. Note*Hint* Pages 136-137 from the book contain much of the code and you are welcome to reference them; just make sure you understand it (these slides will be posted to Moodle for your reference). 3. Finally, modify your code from Homework 4 once again, this time using the DoublyLiked List. (Again, only parts 1-3) Make sure to submit Java files for your SinglyLinkedList, DoublyLinkedList, GameEntry and both Scoreboards. As always, attach screenshots to demonstrate your code works. Note: Sorting with Linked List can be challenging. We have yet to really discuss the nature of sorting algorithms, so for this assignment your Linked Lists do not have to be sorted. Homework 4 Due February 16th 11:00 AM 100 points CS 2235 Data Structures and Algorithms 1. Using the Scoreboard and GameEntry classes from the lecture (these will be posted to Moodle), create a Scoreboard that can contain up to 20 GameEntry objects. 2. Now, create 20 new GameEntry objects with a name (Player 1, Player 2, etc.) and a random score between 0 and 1000, and add them to your Scoreboard array using the add method. Hint: The easiest way to create your GameEntries is to use a loop. 3. Create a method inside the Scoreboard class that prints all the elements inside the array to the screen. Then create another method which displays a summary of the array. This method must include: the number of elements inside the scoreboard, the highest and lowest values, range of scores and the average value of the scoreboard. Demonstrate that both methods work

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!