Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

TestQuestion.java ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; class TestQuestion { @Test void testConstructor() { Question q = new Question(What is Jamie's dog's name?, Bibbet); assertEquals(1,

TestQuestion.java

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

class TestQuestion {

@Test void testConstructor() { Question q = new Question("What is Jamie's dog's name?", "Bibbet"); assertEquals(1, q.getDifficulty()); assertEquals("What is Jamie's dog's name?", q.getQuestion()); assertEquals("Bibbet", q.getAnswer()); Question q2 = new Question("",""); assertEquals(1, q2.getDifficulty()); assertEquals("", q2.getQuestion()); assertEquals("", q2.getAnswer()); Question q3 = new Question(null,null); assertEquals(1, q3.getDifficulty()); assertNull(q3.getQuestion()); assertNull(q3.getAnswer()); } @Test void testOverloadedConstructor() { Question q = new Question("What breed is Bibbet?","Boston Terrier", 3); assertEquals(3, q.getDifficulty()); assertEquals("What breed is Bibbet?", q.getQuestion()); assertEquals("Boston Terrier", q.getAnswer()); Question q2 = new Question("","",5); assertEquals(5, q2.getDifficulty()); assertEquals("", q2.getQuestion()); assertEquals("", q2.getAnswer()); Question q3 = new Question(null,null,10); assertEquals(10, q3.getDifficulty()); assertNull(q3.getQuestion()); assertNull(q3.getAnswer()); Question q4 = new Question("What color are Bibbet's eyes?", "Brown", 11); assertEquals(10, q4.getDifficulty()); Question q5 = new Question("What color is Bibbet?", "Black and White", 0); assertEquals(1, q5.getDifficulty()); } @Test void testIsCorrect() { Question q = new Question("What color is Bibbet?", "Black and White", 1); assertTrue(q.isCorrect("Black and White")); assertTrue(q.isCorrect("black and white")); assertFalse(q.isCorrect("white and black")); assertFalse(q.isCorrect("")); assertFalse(q.isCorrect(null)); Question q2 = new Question("How old is Bibbet", "1"); assertTrue(q2.isCorrect("1")); assertFalse(q2.isCorrect("")); assertFalse(q2.isCorrect(null)); }

@Test void testToString(){ Question q = new Question("What color is Bibbet?", "Black and White", 5); String result = "What color is Bibbet? Black and White 5"; assertEquals(result, q.toString()); Question q2 = new Question("How cute is Bibbet?", "The cutest"); result = "How cute is Bibbet? The cutest 1"; assertEquals(result, q2.toString()); Question q3 = new Question("",""); assertEquals(" 1", q3.toString()); Question q4 = new Question(null, null, 5); assertEquals("null null 5", q4.toString()); } @Test void testGetSetQuestion() { Question q = new Question("",""); assertEquals("", q.getQuestion()); q.setQuestion("What is Bibbet's nickname?"); assertEquals("What is Bibbet's nickname?", q.getQuestion()); Question q2 = new Question("What is Bibbet's nickname?", "Spooky Boo", 10); assertEquals("What is Bibbet's nickname?", q2.getQuestion()); q2.setQuestion(""); assertEquals("", q2.getQuestion()); q2.setQuestion(null); assertNull(q2.getQuestion()); } @Test void testGetSetAnswer() { Question q = new Question("",""); assertEquals("", q.getAnswer()); q.setAnswer(null); assertNull(q.getAnswer()); Question q2 = new Question("What is Bibbet's favorite toy?", "Christmas Hedgehog", 10); assertEquals("Christmas Hedgehog", q2.getAnswer()); q2.setAnswer("Squeaky Fox"); assertEquals("Squeaky Fox", q2.getAnswer()); } @Test void testGetSetDifficulty() { Question q = new Question("",""); assertEquals(1, q.getDifficulty()); q.setDifficulty(5); assertEquals(5, q.getDifficulty()); q.setDifficulty(-5); assertEquals(1, q.getDifficulty()); q.setDifficulty(15); assertEquals(10, q.getDifficulty()); Question q2 = new Question("What does Bibbet eat?","Kibble", 1); assertEquals(1, q2.getDifficulty()); q.setDifficulty(0); assertEquals(1, q2.getDifficulty()); } } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Exercise 1 Create a class called Question that simulates short-answer style questions to be placed on a quiz. Each Question object should have a question, an answer, and a difficulty level.

The difficulty level should be an integer between 1 and 10 that represents the difficulty level of the question (1 being easy, 10 being hard).

Overload the constructor so that it only accepts 2 parameters, the question and answer, and sets the difficulty to a default value of 1.

Make sure to use the this keyword. Create the getters and setters for the instance data of this class.

Create a toString method that returns a string summary of the Question object.

Create a method boolean isCorrect(String attemptedAnswer) that returns true if the attempted answer is the correct answer for the current question.

Exercise 2 Download and run the TestQuestion and ensure that your Question class passes all of the JUnit tests. Do not modify the unit test file.

Exercise 3 Create a class called Quiz that uses your Question class to create Quiz objects. A Quiz can be composed of up to 25 questions and a score. The Quiz constructor should initialize an ArrayList and the score accordingly. Create a way to keep track of the total number of quizzes ever created. Create a method called void add(Question q) that adds a new question to the quiz. What should happen if we try to add a 26th question to a quiz? Create only the necessary getters and setters. Create a method called void giveQuiz() that presents each question, and its difficulty, in turn to the user, accepts an answer for each one, and keeps track of the results.

Exercise 4 Create a tester class (read: not a JUnit test class) called QuizTime that creates and populates a Quiz, presents it, and prints the final results. Pick an interesting topic to make your quiz about. To the right is a Sample Output for one execution of QuizTime.

Exercise 5 Currently the difficulty of the questions is not used in creating the quizzes. Overload the giveQuiz method in the Quiz class so that it accepts two integer parameters that specify the minimum and maximum difficulty levels for the quiz questions and presents only questions in that difficulty range. Hint: work smarter not harder, dont duplicate code. If your overridden method contains almost all of the same lines of code as the original giveQuiz method, youre doing it wrong. Create another Quiz in your tester class that demonstrates this new feature. Also demonstrate that you successfully track the total number of quizzes created. To the right is a Sample Output for one execution of QuizTime

image text in transcribedimage text in transcribed

0 Gen 9 x 8 P Q ch | 6 Cu | G ct= 0 ch 0 Ge | C | 4 so | M N O C 0 2 + - [ x G Sig | Ca Co | co D rev | | | | W | CP us | 0 Set V Jav C o O File C:/Users/Arihant%20Singla/Downloads/Lab%203.pdf Exercise 1 Create a class called Question that simulates short-answer style questions to be placed on a quiz. Each Question object should have a question, an answer, and a difficulty level. The difficulty level should be an integer between 1 and 10 that represents the difficulty level of the question (1 being easy, 10 being hard). Overload the constructor so that it only accepts 2 parameters, the question and answer, and sets the difficulty to a default value of 1. Make sure to use the this keyword. Create the getters and setters for the instance data of this class. Create a toString method that retums a string summary of the Question object. Create a method boolean isCorrect(String attemptedAnswer) that retums true if the attempted answer is the correct answer for the current question. Exercise 2 Downloud and run the TestQuestion and ensure that your Question class passes all of the JUnit tests. Do not modify the unit test file. Exercise 3 Create a class called Quiz that uses your Question class to create Quiz objects. A Quiz can be composed of up to 25 questions and a score. The Quiz constructor should initialize an ArrayList and the score accordingly, Create a way to keep track of the total number of quizzes ever created. Create a method called void add(Question q) that adds a new question to the quiz. What should happen if we try to add a 26 question to a quiz? Create only the necessary getters and setters. Create a method called void giveQuiz() that presents each question, and its difficulty, in turn to the user, accepts an answer for each one, and keeps track of the results. E TestOuestion Java Lab 3 (11.pdf Lab 3.pdf Show all X Type here to search O e 9 5 5 A ) 00:42 ENG 29-01-2020 0 Gen 9 x 8 P Q ch | 6 Cu | G ct= 0 ch 0 Ge | C | 4 so | M N O C 0 2 + - [ x G Sig | Ca Co | co C O D rev | | | | W | CP us | 0 Set V Jav File C:/Users/Arihant%20Singla/Downloads/Lab%203.pdf What color is Mars? (Difficulty: 5) Exercise 4 What color is the sky? (Difficulty: 1) What color is the grass? (Difficulty: 1) Create a tester class (read: not a JUnit test class) called Quiz Time that creates and populates a Quiz, presents it, and prints the final results. Pick an interesting topic to make your quiz about. To the right is a sample Output for one execution of Quiz Time What color is the sun? Difficulty: 2) What color is an orange(Difficulty: 1) score is: 1 Exercise 5 Currently the difficulty of the questions is not used in creating the quizzes. Overload the giveQuiz method in the Quiz class so that it accepts two integer parameters that specify the minimum and maximum difficulty levels for the quiz questions and presents only questions in that difficulty range. Hint: work smarter not harder, don't duplicate code. If your overridden method contains almost all of the same lines of code as the original giveQuiz method, you're doing it wrong. You have 2 quizzes to do What color is Love? (Difficulty: 10) what color is Anger? (Difficulty: 10) Correct! What color is Pain? (Difficulty: 10) Correct! Your score is: 3 Create another Quiz in your tester class that demonstrates this new feature. Also demonstrate that you successfully track the total number of quizzes created To the right is a sample Output for one execution of Quiz Time Marking Rubric: Style, Convention, Documentation 15 marks Question.java 9 marks +1.5 instance data +2 constructor +2 overload constructor correctly +2.5 get/set question/answer/difficulty Quiz.java (22 marks +2 instance data +1 tracking total quizzes +5 constructor +2 for getting total quizzes correctly +2 addQuestion +1 for getting score correctly +7 for give quiz +2 for correctly overloading give quiz E TestOuestion Java A Lab 3 (11.pdf A Lab 3.pdf Show all X Type here to search A ) 00:42 ENG 29-01-2020 0 Gen 9 x 8 P Q ch | 6 Cu | G ct= 0 ch 0 Ge | C | 4 so | M N O C 0 2 + - [ x G Sig | Ca Co | co D rev | | | | W | CP us | 0 Set V Jav C o O File C:/Users/Arihant%20Singla/Downloads/Lab%203.pdf Exercise 1 Create a class called Question that simulates short-answer style questions to be placed on a quiz. Each Question object should have a question, an answer, and a difficulty level. The difficulty level should be an integer between 1 and 10 that represents the difficulty level of the question (1 being easy, 10 being hard). Overload the constructor so that it only accepts 2 parameters, the question and answer, and sets the difficulty to a default value of 1. Make sure to use the this keyword. Create the getters and setters for the instance data of this class. Create a toString method that retums a string summary of the Question object. Create a method boolean isCorrect(String attemptedAnswer) that retums true if the attempted answer is the correct answer for the current question. Exercise 2 Downloud and run the TestQuestion and ensure that your Question class passes all of the JUnit tests. Do not modify the unit test file. Exercise 3 Create a class called Quiz that uses your Question class to create Quiz objects. A Quiz can be composed of up to 25 questions and a score. The Quiz constructor should initialize an ArrayList and the score accordingly, Create a way to keep track of the total number of quizzes ever created. Create a method called void add(Question q) that adds a new question to the quiz. What should happen if we try to add a 26 question to a quiz? Create only the necessary getters and setters. Create a method called void giveQuiz() that presents each question, and its difficulty, in turn to the user, accepts an answer for each one, and keeps track of the results. E TestOuestion Java Lab 3 (11.pdf Lab 3.pdf Show all X Type here to search O e 9 5 5 A ) 00:42 ENG 29-01-2020 0 Gen 9 x 8 P Q ch | 6 Cu | G ct= 0 ch 0 Ge | C | 4 so | M N O C 0 2 + - [ x G Sig | Ca Co | co C O D rev | | | | W | CP us | 0 Set V Jav File C:/Users/Arihant%20Singla/Downloads/Lab%203.pdf What color is Mars? (Difficulty: 5) Exercise 4 What color is the sky? (Difficulty: 1) What color is the grass? (Difficulty: 1) Create a tester class (read: not a JUnit test class) called Quiz Time that creates and populates a Quiz, presents it, and prints the final results. Pick an interesting topic to make your quiz about. To the right is a sample Output for one execution of Quiz Time What color is the sun? Difficulty: 2) What color is an orange(Difficulty: 1) score is: 1 Exercise 5 Currently the difficulty of the questions is not used in creating the quizzes. Overload the giveQuiz method in the Quiz class so that it accepts two integer parameters that specify the minimum and maximum difficulty levels for the quiz questions and presents only questions in that difficulty range. Hint: work smarter not harder, don't duplicate code. If your overridden method contains almost all of the same lines of code as the original giveQuiz method, you're doing it wrong. You have 2 quizzes to do What color is Love? (Difficulty: 10) what color is Anger? (Difficulty: 10) Correct! What color is Pain? (Difficulty: 10) Correct! Your score is: 3 Create another Quiz in your tester class that demonstrates this new feature. Also demonstrate that you successfully track the total number of quizzes created To the right is a sample Output for one execution of Quiz Time Marking Rubric: Style, Convention, Documentation 15 marks Question.java 9 marks +1.5 instance data +2 constructor +2 overload constructor correctly +2.5 get/set question/answer/difficulty Quiz.java (22 marks +2 instance data +1 tracking total quizzes +5 constructor +2 for getting total quizzes correctly +2 addQuestion +1 for getting score correctly +7 for give quiz +2 for correctly overloading give quiz E TestOuestion Java A Lab 3 (11.pdf A Lab 3.pdf Show all X Type here to search A ) 00:42 ENG 29-01-2020

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions