Tuesday, July 19, 2011

Question Node Class

This class is also fairly straightforward. These class represents a node in a linked list of Question objects. Each node stores a boolean value indicating whether or not the node's question has ever been accessed, a reference to the next QuestionNode in the list, and a Question object. This class will be located within the QuestionQueue class since only the QuestionQueue will need to access it. 

private class QuestionNode
/*** Description ***
* This class represents a single node in a one directional list of questions. 

*** Notes ***
* There is no setter method for 'next'. Instead, the outer class
* directly sets this variable value (ex: thisNode.next = ...). 
* This is because passing an entire Question object is pointless 
* since this is already a private class. 

* Accessor methods are still used simply for code clarification.
*
*** Variables ***
*
* q - the Question object this node holds
* next - the next QuestionNode in the list
* used - tracks whether the Question this node holds has been used or not

*** Methods ***
*
* Constructor - Expects a Question object to hold. 

* getQuestion - Accessor method for q. Also sets used to true.
* used   - Accessor method for used.
* getNext   - Accessor method for next.

* setNext(QuestionNode) - Setter method for next. 
*/
{
private Question q;
private QuestionNode next;
private boolean used;

public QuestionNode (Question q)
{
this.q = q;
this.next = null;
}

public Question getQuestion()
{
this.used = true;
return q; 
}

public boolean used()
{
return used;
}

public QuestionNode getNext()
{
return next;
}

}

No comments:

Post a Comment