Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this exercise, we will modify the Quiz program from the previous assignment(on the top). we will make a separate class for quiz questions, and

image text in transcribed
In this exercise, we will modify the Quiz program from the previous assignment(on the top). we will make a separate class for quiz questions, and we will create objects of that class to ask questions and check answers. This exercise will include multiple cut-and-paste operations from the existing "Quiz" class into the new "MultipleChoiceQuestion" class. Object-oriented programming is designed to avoid cut and paste, and you will see some of the techniques for re-using existing code in the next assignment. In this exercise , however, you will be converting from procedural programming to object-oriented programming, and cut-and-paste is a simple strategy for this conversion. First make the new "MultipleChoiceQuestion" class. Open your "CS1102" project in Eclipse. Select "New" -> "Class" from the File menu. Enter the Name "MultipleChoiceQuestion" and click "Finish". The new file "MultipleChoiceQuestion.java" should appear in the editor pane. Make sure it is also listed under "(default package)" in the "Package Explorer" pane, along with "Quiz.java". Having both files in the same package eliminates complications with package imports and access specifiers when the "Quiz" class tries to use the "MultipleChoiceQuestion" class. Add class variables and instance variables to the "MultipleChoiceQuestion" definition. Copy the class variables "nQuestions" and "nCorrect" from the "Quiz" class and paste them into the "MultipleChoiceQuestion" class. static int nQuestions = 0; static int nCorrect = 0; Add instance variables for the question and correct answer. Like class variables, these go inside the class definition for "MultipleChoiceQuestion". String question: String correctAnswer; Now add a constructor for "MultipleChoiceQuestion" objects. Name the constructor "MultipleChoiceQuestion". Remember that constructors have no return type. Their name is the return type! Give the constructor 7 parameters, all of type String, named the following o query o a,b,c,d,ande o answer Thus, the constructor should start as follows. e, String answer) { MultipleChoiceQuestion(String query, String a, String b. String c, String d, String

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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 Programming questions

Question

1. Which is the most abundant gas presented in the atmosphere?

Answered: 1 week ago