Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package question2;
- public class Quiz /*extends FillInTheBlank*/{
- private int numQuestions;
- private String title;
- private FillInTheBlank[] quiz;
- /**
- * Argumented Constructor
- * @param numQuestions is the number of questions
- * @param title is the title of the quiz
- */
- public Quiz(int numQuestions, String title) {
- this.numQuestions = 5;
- this.title = "Good Title";
- }
- /**
- * Constructor creates 5 quizzes and sets them to null
- * @param in is the quiz
- */
- public Quiz(Quiz in){
- for(int i = 0; i < numQuestions; i++){
- quiz[i] = null;
- }
- }
- /**
- * Sets the title of the quiz
- * @param title is the title of the quiz
- */
- public void setTitle(String title) {
- this.title = title;
- }
- /**
- * Adds the complete question to the quiz array
- * @param index is the number of the quiz selected
- * @param questionIn is the complete question
- */
- public void setQuestion(int index, FillInTheBlank questionIn) {
- quiz[index] = questionIn;
- }
- /**
- * Gets the title of the quiz
- * @return the title
- */
- public String getTitle() {return title;}
- /**
- *
- * @param index is the number of the quiz selected
- * @return the question found under the index given
- */
- public FillInTheBlank getQuestion(int index) {return quiz[index];}
- /**
- * Checks to see if there are any unanswered questions, and if not, prints only the questions
- */
- public void printText() {
- for(int i = 0; i < quiz.length; i++) {
- if(quiz[i] == null) {
- break;
- }
- else if(i == 4) {
- System.out.println("Questions:");
- for(int c = 1; c <= quiz.length; c++) {
- System.out.println("Q" + c + ". " + quiz[c]);
- }
- }
- }
- }
- /**
- * Checks to see if there are any unanswered questions, and if not, prints only the answers
- */
- public void printAnswers() {
- for(int i = 0; i < quiz.length; i++) {
- if(quiz[i] == null) {
- break;
- }
- else if(i == 4) {
- System.out.println("Questions:");
- for(int c = 1; c <= quiz.length; c++) {
- System.out.println("Q" + c + ". " + quiz[c]);
- }
- }
- }
- }
- /**
- * Outputs the title ad the amount of questions it contains
- */
- public String toString() {
- return "The quiz titled '" + title + "' contains " + numQuestions + " questions.";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement