import android.content.Context;
@SuppressWarnings("rawtypes")
public class Category implements Comparable
/***
*** Description ***
*
* This class defines a Category object. Each Category contains a name, a list of questions,
* and an array of integers representing the number of questions at each difficulty level.
*
*** Attributes ***
*
* String name - The name of the category
* int [] levels - The number of questions at each difficulty level
* Queue<Question> - A Queue<T> of Question objects
*
*** Methods ***
*
* Constructor: Requires a context and a name. Initializes all attributes.
*
* addQuestion: Increments the appropriate levels[] index and enqueues the passed Question.
* getName: Returns the name
* getQuestionsAtLevel: returns the number of questions available at the passed integer difficult level
* getQuestions: Returns the Queue<Question> object
* toString: returns name
* compareTo: returns -1 if passed object is not a category, 1 if it is a different Category, or 0 if the same
*
*/
{
private String name;
private int [] levels; // levels[0] = easy; levels[1] = normal; levels[2] = genius
private Queue<Question> questions;
public Category (Context c, String name)
{
this.name = name;
this.levels = new int[c.getResources().getInteger(R.integer.number_of_levels)];
this.questions = new Queue<Question>();
}
public void addQuestion (Question q)
{
levels[q.getLevel()]++;
questions.enqueue(q);
}
public String getName()
{
return name;
}
public int getQuestionsAtLevel(int j)
{
int numQs = 0;
for (int i = 0; i <= j; i++)
numQs+= levels[i];
return numQs;
}
public Queue<Question> getQuestions()
{
return questions;
}
public int compareTo(Object another) {
if (another instanceof Category)
{
if (this.toString().equals(another.toString()))
{
return 0;
}
else
return 1;
}
return -1;
}
public String toString()
{
return name;
}
}
< Back to Q and A System Take 2
No comments:
Post a Comment