Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

tutorial_inheritance-RexReubens-master/.classpath tutorial_inheritance-RexReubens-master/.gitignore /bin/ tutorial_inheritance-RexReubens-master/.project Quiz_tutorial org.eclipse.jdt.core.javabuilder...

1 answer below »
tutorial_inheritance-RexReubens-maste
.classpath

    
    
    
tutorial_inheritance-RexReubens-maste
.gitignore
in
tutorial_inheritance-RexReubens-maste
.project

     Quiz_tutorial
    
    
    
    
        
             org.eclipse.jdt.core.javabuilde
            
            
        
    
    
         org.eclipse.jdt.core.javanature
    
tutorial_inheritance-RexReubens-maste
README.md
# Inheritance_n_Polymorphism
In this exercise we are going to practice a few code related to inheritance and polymorphism. We are going to design a **Quizz** where a set of different types of questions like short question, MCQ, true/false will be displayed to the user and will collect response from the user. Also the program will check whether the response is rigth or wrong.
# What you have in the starter code
- We have a generic class called **Question** that has two member variables **text**, **answer** and a method
called **checkAnswer** as described bellow:
- **text**: stores the description of the question
- **answer**: stores the co
ect answer for the question
- **checkAnswer(String ans)**: That takes the answer as an argument/parameter and checks whether it is co
ect or not. It returns *true* if the answer matched with the co
ect answer stored in the variable **answer**, otherwise returns *false*.
You also have a **Main** class that demonstrate the use of the **Qustion**.
# What you have to do
## Task 1
- Import the project in *eclipse* from the repository.
- Run the program and see how it works.
- Try to understand the code and what it is doing.
## Task 2
- Create a new class called **MCQQuestion** that extends the class **Question**.
- Your **MCQQuestion** class should have the following members:
- An A
ayList **choices** to store the list of choices for a question.
- A constructor that creates the A
ayList
- A method **addChoice(String choice, boolean co
ect)** that adds choices for a question and stores as the answer for the question if the co
ect is *true*.
- A method **display()** that ove
ides the display method of the super class to display the MCQ question properly with choices.
- Rewrite the **Main** class to display a MCQ question and take a response from keyboard for the answer as the choice (1,2 ..)
- Display if the answer is co
ect or not.
- The screen may look like:
```
In which country was the inventor of Java born?
1: Canada
2: United States
3: Denmark
4: United State
Your answer: 1
true
```
## Task 3
- Create a new class called **Quiz** that will store a list of questions.
- Add a method called **addQuestion(Question Q)** that can add any type of question in the list.
- Add a method called **allQuestions()** that returns the list of questions added to a Quiz.
- Rewrite the **Main** class that creates a **Quiz** object and adds at least three different questions with answers in order: first one is a regular question, second one is an MCQ, third one is a regular question and so on (Try to make your questions as difficult as possible).
- Now display the questions from the Quiz one at a time and take a respose from the user.
- Display whether the result is co
ect or not.
- You may declare any helper method, or getter and setter or constructor if necessary.
## Task 4
- Now change the **Question** class as an Abstract class and change display as an abstract method.
- Try to run the program and see what e
ors you get.
- Try to fix those e
ors.
- Now we don't have an inherited method display.
- Create a new extended class from **Question** as **ShortQuestion**.
- Use this **ShortQuestion** as we used the generic **Question** and rewrite your program.
- Try to compile the **ShortQuestion** without ove
iding the **display()** method.
- Write necessary code to fix the e
ors.
tutorial_inheritance-RexReubens-maste
src/Inheritance/Main.java
tutorial_inheritance-RexReubens-maste
src/Inheritance/Main.java
package Inheritance;
import java.util.A
ayList;
import java.util.Scanner;
**
This program shows a simple quiz with one question.
 *
public class Main
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        Question q = new Question();
        q.setText("Who was the inventor of Java?");
        q.setAnswer("James Gosling");
        q.display();
        System.out.print("Your answer: ");
        String response = in.nextLine();
        System.out.println(q.checkAnswer(response));
    }
}
tutorial_inheritance-RexReubens-maste
src/Inheritance/Question.java
tutorial_inheritance-RexReubens-maste
src/Inheritance/Question.java
package Inheritance;
**
2 A question with a text and an answer.
3 *
public class Question
{
    private String text;
    private String answer;
    /**
 Constructs a question with empty question and answer.
     *
    public Question()
    {
        text = "";
        answer = "";
    }
    /**
 Sets the question text.
@param questionText the text of this question
     *
    public void setText(String questionText)
    {
        text = questionText;
    }
    /**
 Sets the answer for this question.
 @param co
ectResponse the answe
     *
    public void setAnswer(String co
ectResponse)
    {
        answer = co
ectResponse;
    }
    /**
 Checks a given response for co
ectness.
 @param response the response to check
 @return true if the response was co
ect, false otherwise
     *
    public boolean checkAnswer(String response)
    {
        return response.equals(answer);
    }
    /**
 Displays this question.
     *
    public void display()
    {
        System.out.println(text);
    }
    
public abstract void display();
}
Answered Same Day Feb 26, 2021

Solution

Aditya answered on Feb 26 2021
148 Votes
tutorialinheritance-rexreubens-master-walzawo1/.project

     tutorialinheritance-rexreubens-master-walzawo1
    
    
    
    
    
    
    
tutorialinheritance-rexreubens-master-walzawo1/tutorial_inheritance-RexReubens-maste
.classpath

    
    
    
tutorialinheritance-rexreubens-master-walzawo1/tutorial_inheritance-RexReubens-maste
.gitignore
in
tutorialinheritance-rexreubens-master-walzawo1/tutorial_inheritance-RexReubens-maste
.project

     Quiz_tutorial
    
    
    
    
        
             org.eclipse.jdt.core.javabuilde
            
            
        
    
    
         org.eclipse.jdt.core.javanature
    
tutorialinheritance-rexreubens-master-walzawo1/tutorial_inheritance-RexReubens-maste
in/Inheritance/Main.class
tutorialinheritance-rexreubens-master-walzawo1/tutorial_inheritance-RexReubens-maste
in/Inheritance/MCQQuestion.class
tutorialinheritance-rexreubens-master-walzawo1/tutorial_inheritance-RexReubens-maste
in/Inheritance/Question.class
tutorialinheritance-rexreubens-master-walzawo1/tutorial_inheritance-RexReubens-maste
README.md
# Inheritance_n_Polymorphism
In this exercise we are going to practice a few code related to inheritance and polymorphism. We are going to design a **Quizz** where a set of different types of questions like short question, MCQ, true/false will be displayed to the user and will collect response from the user. Also the program will check whether the response is rigth or wrong.
# What you have in the starter code
- We have a generic class called **Question** that has two member variables **text**, **answer** and a method
called **checkAnswer** as described bellow:
- **text**: stores the description of the question
- **answer**: stores the co
ect answer for the question
- **checkAnswer(String ans)**: That takes the answer as an argument/parameter and checks whether it is co
ect or not. It returns *true* if the answer matched with the co
ect answer stored in the variable **answer**, otherwise returns *false*.
You also have a **Main** class that demonstrate the use of the **Qustion**.
# What you have to do
## Task 1
- Import the project in *eclipse* from the repository.
- Run the program and see how it works.
- Try to understand the code and what it is doing.
## Task 2
- Create a new class called **MCQQuestion** that extends the class **Question**.
- Your **MCQQuestion** class should have the following members:
- An A
ayList **choices** to store the list of choices for a...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here