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;
}

}

asked by Tim
  1. Anyone?

    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.

    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;

    }

    posted by Tim

Respond to this Question

First Name

Your Response

Similar Questions

  1. Java Programming

    Hey! Thanks for checking my question out! ____ 10. If x is a sorted array of int values, which of the following shows a call to a method of the Arrays class that will determine if the value 7 exists in the array? (1 point) a) int
  2. Science

    Intrinsic control of heartbeat rate involves what mechanism(s)? a) The AV node initiates heartbeat although the SA node can generate a slower beat rate. b) The atrioventricular bundle initiates signals that travel to the Purkinje
  3. ISDS

    The optimal total shipping cost in a minimization transportation model is $622, and the reduced cost from source node 1 to destination node 6 is $6. This implies that if one were to deviate from the optimal solution by shipping
  4. isds

    The optimal total shipping cost in a minimization transportation model is $622, and the reduced cost from source node 1 to destination node 6 is $6. This implies that if one were to deviate from the optimal solution by shipping
  5. advance icd-9

    This 35-year-old female patient has carcinoma of the upper-outer left breast. She had a lumpectomy performed and a sentinel lymph node biopsy of the axillary lymph node. The pathology report for the lymph node states no
  6. Medical

    This 35 year old female patient has carcinoma of the upper-outer left breast. She had a lumpectomy performed and a sentinel lymph node biopsy of the axillary lymph node. The pathology report for the lymph node states no
  7. java

    Write the following methods and test them.this need to be execute it in Eclipse IDE for Java Developers 1. printVowels - this method should take a String as a parameter and print all the vowels contained in that String one
  8. Physics

    The wavelength of a stationary wave is 36.0cm. What is the distance between a node and the next anti -node
  9. Horticulture

    The repeated node internode node pattern of construction is typical of what part of an angiosperm plant?
  10. coding

    This 35 years old female patient has carcinoma of the upper-outer left breast. She had a lumpectomy performed and a sentinel lymph node biopsy of the axillary lymph node. The pathology report for the lymph node. Diagnosis code

More Similar Questions