HELLO, PLEASE YOU DON\'T NEED TO GIVE ME CODES FOR THIS PROGRAM BUT I JUST WANT
ID: 3723410 • Letter: H
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. 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
Explanation / Answer
hi, let me put this up into simple statements. Your assignment have 2 classes:
1> GameEntry
This class is just to contain the name and score values for the player. So the object of this class will contain two fields, name and score. Name is basically the player's name and his score. Lets call each set of player name and his score as 'record'.
2> GameEntryList
This class is basically a list of such record . So, this class is just like a linked list of Integers. In this case, its a list of record(GameEntry). You need to add methods to add into the list, delete from the list, view the list(print the list).
3> TestGameList
the purpose of this class is to test the proper functioning of the above two classes.You will write your main() method in this class and will create objects of the above classes and use their methods for the respective operations.
feel free to ask if you have any doubts :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.