Question
HELLO, PLEASE YOU DON'T NEED TO GIVE ME CODES FOR THIS PROGRAM BUT I JUST WANT TO KNOW THE PURPOSE OF EACH CLASS EXPLANATION PLEASE.
HELLO, PLEASE YOU DON'T NEED TO GIVE ME CODES FOR THIS PROGRAM BUT I JUST WANT TO KNOW THE PURPOSE OF EACH CLASS EXPLANATION PLEASE. MY CLASSES ARE FOLLOWING: TestGameList, GameEntryList, AND GameEntry. THANK YOU
For this project, you will create a singly linked list of GameEntry objects to maintain the top scores for a video game. The GameEntry class is provided as below,
public class GameEntry {
private String name;
private int score;
public GameEntry(String name, int score) {
this.name = name;
this.score = score;
}
public String getName() {
return name;
}
public int getScore() {
return score;
}
public String toString() {
return "[" + name + "," + score + "]";
}
}
Start the project by creating a class named GameEntryList, using a singly linked list as the data structure for this task. In addition to the head field that we discussed with in class, you will also maintain a tail field. Include the below standard linked list methods. Implement all the method headers exactly as given below.
Basic features of GameEntryList:
A head field that references the first node in the list
A size field for the total number of nodes in the list.
A tail field that references the last node in the list (akin to the head field)
This field must be updated during operations like removing and adding nodes in case the last (or only) node is removed or a new node is being added to the end of the list.
The end of the list could be the same as the beginning of the list if there is only one item in it.
It is initially set to null, when the list is empty, just like the head field.
A constructor method creates a new empty linked list
/**
Constructor that creates an empty list
public GameEntryList()
A display() method outputs all the game entries in the list. Remember, GameEntry objects come with a toString()method (see its definition in the GameEntry class), so you can directly print a GameEntry object e simply with System.out.println(e).
/**
Prints out all the game entries in the linked list
*/
public void display()
An addFirst(GameEntry entry) method adds the node v to the front of the list
/**
Add a node to the head of the list
@param entry the game entry to be added
*/
public void addFirst(GameEntry entry)
A removeFirst() method removes a node from the front of the list
/**
Removes the first node and returns it.
@return the game entry that was removed
*/
public GameEntry removeFirst()
An addLast(GameEntry entry) method adds the GameEntry entry to the end of the list. Note: now that we have a reference to the tail of the list, this method can be implemented much simpler!
/**
Add a node to the tail of the list
@param entry the game entry to be added
*/
public void addLast(GameEntry entry)
A removeLast()method remove the last entry from the list.
/**
Remove the last entry from the list and return it.
@return the game entry that was removed
*/
public GameEntry removeLast()
An add(GameEntry entry) method, which only needs to work properly when the items in the list are already ordered by scores from highest to lowest. You may review Lecture notes CSC330 Lecture 2 Array.pptx on the Blackboard for the array implementation of the algorithm.
/**
Assuming the list of game entries is in decreasing order by score, this method creates a Node with the given GameEntry entry, and then add it in the appropriate spot in the list.
@param e the GameEntry object to be added to the list
*/
public void add(GameEntry entry)
remove(int i) removes the ith node, returning the corresponding game entry object
/**
Removes the node at position i in the list (emulating an array index)
@return GameEntry of the removed node or null if position i is invalid
*/
public GameEntry remove(int
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started