Programming

Hey guys, I seem to be having a bit of trouble with my assignement involving linked lists in java. The problem is with creating the node. My professor asks that we create a string and int in the node, but all examples that I have found only use one node. Heres the assignment:

In addition to linked lists, you will demonstrate your understanding of many components discussed this semester including inheritance. Everyone must use inheritance to create a linked list class and an application that tracks the name and score of the top 10 gamers using the linked list class. Duplicate entries are allowed in the list. Only the top 10 scores will be maintained. When the list contains 10 entries and a new entry is attempted, the application should only add the new entry if the score exceeds the lowest score on the list. In that case, the lowest score currently on the list should be dropped.

Java defines a LinkedList class in java.util. Your GameLinkedList class should extend this class and implement the GameLinkedListInterface (click link to download the interface.)

Eligible points for this project are based upon the items completed. All projects must extend the java.util.LinkedList class and implement the GameLinkedListInterface (option 1).

Option Items Completed
Percentage of the available points
1 Node, GameLinkedList 70%
2 Exception Handling using exception classes + 15%
3 GUI client + 15%

For those not completing Option 3, a keyboard/monitor client is required.



Classes:

Node class

The Node class should define a single name, score, and the next Node object in the Linked List. All Node objects must contain a non-blank name and a score greater than zero.

Options

•(Option 1) Display an error message to System.err object whenever an illegal name or illegal score is encountered.

•(Option 2) The class should throw a IllegalDataFieldException exception (see below) whenever an illegal name or illegal score is encountered.



GameLinkedList class

A customized version of the java.util.LinkedList class, the GameLinkedList class should maintain an ordered linked list of Node objects. The class must implement the GameLinkedListInterface. The class will be responsible for creating new Node objects and adding them to the list when space is available. When the list is full and the new Node's score is greater than the lowest score, the Node containing the lowest score should be removed from the list.

Options

•(Option 1) Display an error message to System.err object whenever a new Node can not be added to the list. Remove the comment from the applicable add method described in the GameLinkedListInterface.

•(Option 2) The class should throw a LinkedListException exception (see below) when a Node can not be created due to illegal data. The exception should also be thrown when the list is full and the score to be added is less than the lowest score on the list. Remove the comment from the applicable add method described in the GameLinkedListInterface.



Exception classes (Option 2 only)

Two exception classes are required, one for Node errors and one for LinkedList errors to respond to the following:

•The IllegalDataFieldException class reports Node errors to the LinkedList class

◦null or blank name

◦score less than 0



•The LinkedListException class reports Linked List errors to the client

◦unsuccessful add due to a Node error or a full list



Client Application:

The client is responsible for retrieving a new name and score entry from the user, sending the information to the Linked List for addition, and displaying the current content of the Link List class.

Options

•(Option 1) The client should utilize the keyboard and monitor. Individual classes are responsible for error reporting.

•(Option 2) The client should utilize the keyboard and monitor. The client is also responsible for displaying any errors that occur during processing.

•(Option 3) Implement the client using a simple GUI interface such as the one shown below. When option 2 is also completed, error reporting should be displayed in the window.



Hints:

The Linked List must be maintained in score order. Therefore, the Node containing the lowest score will be at one end of the list or the other. Before developing the add method, take into consideration the removeLowest method (is it easier to remove a node from the beginning or the end?)

When completing option three, keep it simple. A JTextArea and the GameLinkedList toString method can be used to display the list. Since the data is being managed by the GameLinkedList class, there is no need for JPanel classes.

Read the lab specifications again. There is not a lot of coding! Plus, by completing all three options, you will have reviewed a substantial amount of the material covered on the Final exam ;)

Evaluation:

Classes must compile without syntax errors or will not be evaluated. This lab is worth 30 points. All class should be implemented as outlined above and must adhere to the style guide. Points will be distributed as follows:

•Node class (4 points)
•LinkedList class (15 points)
•IllegalDataFieldException and IllegalLinkedListException classes (4.5 points)
•Client application (2 points) or GUI client application (6.5 points)
•On time (late penalty of 10 points assessed for projects submitted late)

Here is the node code so far:

import java.util.LinkedList;

public class Node
{
private String name;
private int score;
private Node next;


public Node()
{
name = null;
score = 0;
next = null;
}

public Node(String nam, int sco) throws IllegalDataFieldException
{
if (nam == null || sco < 0)
throw new IllegalDataFieldException("No name entered or negative score posted");
else
{
name = nam;
score = sco;
}

next = null;
}

public void setName(String nam)
{
name = nam;
}

public String getName()
{
return name;
}

public void setScore(int sco)
{
score = sco;
}

public int getScore()
{
return score;
}

public void setNext(Node n)
{
next = n;
}

public Node getNext()
{
return next;
}

}

  1. 👍 0
  2. 👎 0
  3. 👁 59
asked by Tim
  1. Anyone?

    1. 👍 0
    2. 👎 0
    posted by Tim
  2. What is the question?

    Have you compiled the code and encountered some problems?

    The Node class looks OK to me, complete with constructors and get/set methods. The state variables are as required by the instructions.

    I have not read through everything in detail, but I do not seem to see code that places the node in a linkedlist, or in fact, there is no code that instantiates nodes.

    In case you have not started reading about java's LinkedList class, here's a link to the API. Notice that the java's LinkedList class does not have an upper limit to the number of nodes. If the initial limit is exceeded, it will extend the list automatically. So you will have to programme the limit in your code as instructed by your project requirements.

    You are on the right track. Please tell us more. For example, you could post your pseudocode for discussion.

    1. 👍 0
    2. 👎 0
    posted by MathMate
  3. Actually I have a few questions:
    How do I create the removeLowest() method if the maximum number of nodes can be up to ten.

    I seem to be having problems with the toString() method, Any suggestions? Heres my code so far:

    import java.util.LinkedList;

    public class GameLinkedList implements GameLinkedListInterface
    {
    private Node head;
    public int MAXSIZE = 10;

    public GameLinkedList()
    {
    head = null;
    }

    public boolean isEmpty()
    {
    if (head == null)
    return true;
    else
    return false;
    }

    public void add(String newName, int newScore) throws LinkedListException
    {
    Node newNode = new Node(newName, newScore);
    if (newName == null || newScore < 0)
    {
    throw new LinkedListException("Illegal Data Given");
    }
    if (isEmpty())
    head = newNode;
    else
    {
    if (head.getScore() > newNode.getScore())
    {
    newNode.setNext(head);
    head = newNode;
    }
    else
    {
    Node current = head;
    while (current.getNext() != null && current.getNext().getScore() < newNode.getScore())
    current = current.getNext();
    newNode.setNext(current.getNext());
    current.setNext(newNode);
    }
    }
    }

    public void removeLowest()
    {
    return;
    }

    public String toString()
    {
    String str;

    Node p = head;
    while (p != null)
    {
    str = (p.getName() + ":" + p.getScore());
    }
    return str;
    }
    }

    Also here is the interface that I have to implement.

    public interface GameLinkedListInterface
    {
    public int MAXSIZE = 10;
    public boolean isEmpty();
    public void removeLowest();
    public String toString();

    public void add(String newName, int newScore) throws LinkedListException;

    }

    1. 👍 0
    2. 👎 0
    posted by Tim

Respond to this Question

First Name

Your Response

Similar Questions

  1. Music Video Project

    Hey guys! I am in a bit of a dilemma. I am doing a music video project for my AP Biology class and My topic is GENE REGULATION! I have no clue what to sing for it. What could be a good chorus? hook? What should be the most

    asked by Sam on March 13, 2012
  2. physics

    hey you guys , i reay appreciate it if you guys help me out . Q: a vector is a physica quantity that has which of the following properties ( can be more than one) a)magnitude b)color c)speed d)direction

    asked by kevin on April 12, 2012
  3. English

    Hey guys, I was just wondering if you could help me find or explain to me media influence in the Hunger Games. I know this is a big part of the story, but I really need clarification. Thanks a lot guys!

    asked by Alex on January 14, 2011
  4. English Intolerance task:

    Hey guys once again. I have trouble between choosing the Johnny Rebel song of "Nigger Hatin Me" OR "Kajun Ku Klux Klan" which one and why? (note: ill need to have some points on how intolerance is demostrated throughout the song

    asked by Shivi on March 7, 2011
  5. genetics/biology

    I am having trouble wording this question. Describe the differences in the outcomes for a dihybrid cross ifgenes are: a. completely linked b. completely unlinked c. incompletely linked.

    asked by Lucylu on April 16, 2012
  6. english

    hey people!! im new here and i just got an essay to do on english altough its the first day of school!! please guys i really need your help.. its a essay on the following topics: 1-summer 2-love is not all it's made out to be 3-a

    asked by wayne on January 21, 2009
  7. english

    Hmm I'm just wondering why no one is helping me and skipping my question yesterday, is it because it's too long or too advanced? I just needed help with my thesis/argument so I can start my essay. I wrote my intro already but it

    asked by Farrell on February 19, 2012
  8. spanish

    hey i'm having a bit of trouble with spanish. Any help with differentiation the two would be great. hace + period of time + que + present tense AND hacía + period of time + que + imperfect tense. I have my spanish book with me,

    asked by Krissy on December 15, 2007
  9. History 9th grade.

    Hey guys! I have a hard time on this question. I would really appreciate it if you could help me :) The question is: How did conflict and cooperation within early civilizations relate to the use of resources? The hard part is

    asked by Misty on September 9, 2017
  10. science

    hey guys, i need help again. wut iz density?

    asked by A7X a.k.a Aaron on October 7, 2009

More Similar Questions