Question: Can you do in a complete code and go through as the instruction provide. Because most of the answer I saw in Chegg, they only

Can you do in a complete code and go through as the instruction provide. Because most of the answer I saw in Chegg, they only gave a code for miniquiz. I want a question code too. Thank you!

Can you do in a complete code and go through as the

instruction provide. Because most of the answer I saw in Chegg, theyonly gave a code for miniquiz. I want a question code too.

A Modified Mini Quiz Class Files Question.java, Complexity.java, and Mini Quiz.java contain the classes in Listings of the text. These classes demonstrate the use of the Complexity interface; class Question implements the interface, and class MiniQuiz creates two Question objects and uses them to give the user a short quiz. Save these three files to your directory and study the code in MiniQuiz.java. Notice that after the Question objects are created, almost exactly the same code appears twice, once to ask and grade the first question, and again to ask and grade the second question. Another approach is to write a method askQuestion that takes a Question object and does all the work of asking the user the question, getting the user's response, and determining whether the response is correct. You could then simply call this method twice, once for ql and once for q2. Modify the MiniQuiz class so that it has such an askQuestion method, and replace the code in main that asks and grades the questions with two calls to askQuestion. Some things to keep in mind: The definition of askQuestion should be inside the MiniQuiz class but after the main method. Since main is a static method, askQuestion must be static too. (A static method cannot call an instance method of the same class.) Also, askQuestion is for use only by this class, so it should be declared private. So the header for askQuestion should look like this: private static void askQuestion (Question question) String possible, which is currently declared in main, will need to be defined in askQuestion instead. You do not need to make any changes to Question.java or Complexity.java. // Question.java Author: Lewis/Loftus // Represents a question (and its answer). public class Question implements Complexity { private String question, answer; private int complexityLevel; //-- // Sets up the question with a default complexity. //--- public Question (String query, String result) question - query; answer = result; complexityLevel = 1; } // Sets the complexity level for this question. public void setComplexity (int level) { complexityLevel = level; // Returns the complexity level for this question. //---- public int getComplexity () { return complexityLevel; } // - // Returns the question. //----- public String getQuestion() return question; } // // Returns the answer to this question. //-- public String getAnswer() return answer; // Returns true if the candidate answer matches the answer. 1/-- public boolean answerCorrect (String candidateAnswer) return answer.equals(candidateAnswer); 11- 1/ Returns this question (and its answer) as a string. //--- public String toString() return question + " " + answer; // Complexity.java Author: Lewis/Loftus // Represents the interface for an object that can be assigned an // explicit complexity. public interface Complexity public void setComplexity (int complexity); public int get Complexity(); ***** MiniQuiz.java Author: Lewis/Loftus // // Demonstrates the use of a class that implements an interface. ******** ******** import java.util.Scanner; public class MiniQuiz { Presents a short quiz. public static void main (String[] args) Question al, 22; String possible; Scanner scan = new Scanner(System.in); ql = new Question ("What is the capital of Jamaica?", "Kingston"); ql.setComplexity (4); q2 = new Question ("Which is worse, ignorance or apathy?", "I don't know and I don't care"); q2.setComplexity (10); System.out.print (ql.getQuestion()); System.out.println(" (Level: " + q1.getComplexity () + " "); possible - scan.nextLine(); if (qi.answerCorrect (possible) System.out.println ("Correct"); else System.out.println ("No, the answer is " + q1.getAnswer()); System.out.println(); System.out.print (92.getQuestion()); System.out.println(" (Level: " + 22.getComplexity () + ")"); possible = scan.nextLine(); if (q2.answerCorrect (possible)) System.out.println ("Correct"); else System.out.println ("No, the answer is " + q2.getAnswer()); } } A Modified Mini Quiz Class Files Question.java, Complexity.java, and Mini Quiz.java contain the classes in Listings of the text. These classes demonstrate the use of the Complexity interface; class Question implements the interface, and class MiniQuiz creates two Question objects and uses them to give the user a short quiz. Save these three files to your directory and study the code in MiniQuiz.java. Notice that after the Question objects are created, almost exactly the same code appears twice, once to ask and grade the first question, and again to ask and grade the second question. Another approach is to write a method askQuestion that takes a Question object and does all the work of asking the user the question, getting the user's response, and determining whether the response is correct. You could then simply call this method twice, once for ql and once for q2. Modify the MiniQuiz class so that it has such an askQuestion method, and replace the code in main that asks and grades the questions with two calls to askQuestion. Some things to keep in mind: The definition of askQuestion should be inside the MiniQuiz class but after the main method. Since main is a static method, askQuestion must be static too. (A static method cannot call an instance method of the same class.) Also, askQuestion is for use only by this class, so it should be declared private. So the header for askQuestion should look like this: private static void askQuestion (Question question) String possible, which is currently declared in main, will need to be defined in askQuestion instead. You do not need to make any changes to Question.java or Complexity.java. // Question.java Author: Lewis/Loftus // Represents a question (and its answer). public class Question implements Complexity { private String question, answer; private int complexityLevel; //-- // Sets up the question with a default complexity. //--- public Question (String query, String result) question - query; answer = result; complexityLevel = 1; } // Sets the complexity level for this question. public void setComplexity (int level) { complexityLevel = level; // Returns the complexity level for this question. //---- public int getComplexity () { return complexityLevel; } // - // Returns the question. //----- public String getQuestion() return question; } // // Returns the answer to this question. //-- public String getAnswer() return answer; // Returns true if the candidate answer matches the answer. 1/-- public boolean answerCorrect (String candidateAnswer) return answer.equals(candidateAnswer); 11- 1/ Returns this question (and its answer) as a string. //--- public String toString() return question + " " + answer; // Complexity.java Author: Lewis/Loftus // Represents the interface for an object that can be assigned an // explicit complexity. public interface Complexity public void setComplexity (int complexity); public int get Complexity(); ***** MiniQuiz.java Author: Lewis/Loftus // // Demonstrates the use of a class that implements an interface. ******** ******** import java.util.Scanner; public class MiniQuiz { Presents a short quiz. public static void main (String[] args) Question al, 22; String possible; Scanner scan = new Scanner(System.in); ql = new Question ("What is the capital of Jamaica?", "Kingston"); ql.setComplexity (4); q2 = new Question ("Which is worse, ignorance or apathy?", "I don't know and I don't care"); q2.setComplexity (10); System.out.print (ql.getQuestion()); System.out.println(" (Level: " + q1.getComplexity () + " "); possible - scan.nextLine(); if (qi.answerCorrect (possible) System.out.println ("Correct"); else System.out.println ("No, the answer is " + q1.getAnswer()); System.out.println(); System.out.print (92.getQuestion()); System.out.println(" (Level: " + 22.getComplexity () + ")"); possible = scan.nextLine(); if (q2.answerCorrect (possible)) System.out.println ("Correct"); else System.out.println ("No, the answer is " + q2.getAnswer()); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!