Can someone please show me how to get this code working correctly. It doesn\'t h
ID: 3543855 • Letter: C
Question
Can someone please show me how to get this code working correctly. It doesn't have to be exact and I know you don't know the exact methodNames or variables, just show how to do the steps listed in this code with accurate java coding.
public Question get(String category, int num) {
// Get the vector of questions from a category file
// Check that the index number is valid (between 0 and the vector size - 1)
// If valid, return the question object else return null
}
Explanation / Answer
public Question get(String category, int num) {
// Get the vector of questions from a category file
Vector<Question> questions = getCategoryFile(category);
// Check that the index number is valid (between 0 and the vector size - 1)
if(num>=0 && num<questions.size()){
// If valid, return the question object
return questions.elementAt(num);
}
else{
// else return null
return null;
}
}