Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. package question2;
  2.  
  3. public class Quiz /*extends FillInTheBlank*/{
  4. private int numQuestions;
  5. private String title;
  6. private FillInTheBlank[] quiz;
  7. /**
  8. * Argumented Constructor
  9. * @param numQuestions is the number of questions
  10. * @param title is the title of the quiz
  11. */
  12. public Quiz(int numQuestions, String title) {
  13. this.numQuestions = 5;
  14. this.title = "Good Title";
  15. }
  16. /**
  17. * Constructor creates 5 quizzes and sets them to null
  18. * @param in is the quiz
  19. */
  20. public Quiz(Quiz in){
  21. for(int i = 0; i < numQuestions; i++){
  22. quiz[i] = null;
  23. }
  24. }
  25. /**
  26. * Sets the title of the quiz
  27. * @param title is the title of the quiz
  28. */
  29. public void setTitle(String title) {
  30. this.title = title;
  31. }
  32. /**
  33. * Adds the complete question to the quiz array
  34. * @param index is the number of the quiz selected
  35. * @param questionIn is the complete question
  36. */
  37. public void setQuestion(int index, FillInTheBlank questionIn) {
  38. quiz[index] = questionIn;
  39. }
  40. /**
  41. * Gets the title of the quiz
  42. * @return the title
  43. */
  44. public String getTitle() {return title;}
  45. /**
  46. *
  47. * @param index is the number of the quiz selected
  48. * @return the question found under the index given
  49. */
  50. public FillInTheBlank getQuestion(int index) {return quiz[index];}
  51.  
  52. /**
  53. * Checks to see if there are any unanswered questions, and if not, prints only the questions
  54. */
  55. public void printText() {
  56. for(int i = 0; i < quiz.length; i++) {
  57. if(quiz[i] == null) {
  58. break;
  59. }
  60. else if(i == 4) {
  61. System.out.println("Questions:");
  62. for(int c = 1; c <= quiz.length; c++) {
  63. System.out.println("Q" + c + ". " + quiz[c]);
  64. }
  65. }
  66. }
  67. }
  68.  
  69. /**
  70. * Checks to see if there are any unanswered questions, and if not, prints only the answers
  71. */
  72. public void printAnswers() {
  73. for(int i = 0; i < quiz.length; i++) {
  74. if(quiz[i] == null) {
  75. break;
  76. }
  77. else if(i == 4) {
  78. System.out.println("Questions:");
  79. for(int c = 1; c <= quiz.length; c++) {
  80. System.out.println("Q" + c + ". " + quiz[c]);
  81. }
  82. }
  83. }
  84. }
  85. /**
  86. * Outputs the title ad the amount of questions it contains
  87. */
  88. public String toString() {
  89. return "The quiz titled '" + title + "' contains " + numQuestions + " questions.";
  90. }
  91.  
  92.  
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement