Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question.java: public abstract class Question { private String qText; private double point; public Question() { this.qText = ; } public Question(String qText) { this.qText =

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedQuestion.java:

public abstract class Question { private String qText; private double point; public Question() { this.qText = ""; } public Question(String qText) { this.qText = qText; }

/** * @return the qText */ public String getqText() { return qText; }

/** * @param qText the qText to set */ public void setqText(String qText) { this.qText = qText; }

/** * @return the point */ public double getPoint() { return point; }

/** * @param point the point to set */ public void setPoint(double point) { this.point = point; } public abstract double grade(String answer); public abstract String getCorrectAnswer(); } MCQuestion.java:

import java.util.ArrayList;

public class MCQuestion extends Question{ private ArrayList options; private String answer; public MCQuestion() { this.options = new ArrayList(); }

/** * @param qText * @param options * @param answer */ public MCQuestion(String qText, ArrayList options, double point) { super(qText); this.options = options; this.setPoint(point);; }

/** * @return the options */ public ArrayList getOptions() { return options; }

/** * @param options the options to set */ public void setOptions(ArrayList options) { this.options = options; } /** * @param options the options to set */ public void setOptions(String options) { this.options.add(options); }

/** * @return the answer */ public String getAnswer() { return answer; }

/** * @param answer the answer to set */ public void setAnswer(String answer) { this.answer = answer; }

@Override public double grade(String answer) { if(getCorrectAnswer().equalsIgnoreCase(answer)) return getPoint(); else return 0; }

@Override public String getCorrectAnswer() { return answer; } } TFQuestion.java:

public class TFQuestion extends Question { private boolean answer; public TFQuestion() { super(); }

/** * @param answer */ public TFQuestion(String qText, boolean answer, double point) { super(qText); this.answer = answer; this.setPoint(point); }

/** * @return the answer */ public boolean isAnswer() { return answer; }

/** * @param answer the answer to set */ public void setAnswer(boolean answer) { this.answer = answer; } @Override public double grade(String answer) { if(getCorrectAnswer().equalsIgnoreCase(answer)) return getPoint(); else return 0; }

@Override public String getCorrectAnswer() { return String.valueOf(answer); } }

//End of code

Hi I have done the classes part . Having problem with the main class. please complete the code and make code completely executable as in shown output.

You are asked to write a Java program for the programming quiz system. There are two types of questions: Multiple Choice Question and Ture/False Question. User can create questions using the system; and preview the quiz, which display all questions in the system one by one. During the preview, the user can attempt the quiz by entering his/her answers to questions. The system will then immediately check the answer and calculate. After attempting all questions, the total score will be displayed. A sample run of the program is shown as below (Green text refers to user input): Please choose (c)reate a question, (p)review or (e)xit >> Enter the type of question (MC or TF) >> MC Enter the question text >> Each primitive type in Java has a corresponding class contained in the java.lang package. These classes are called classes. How many options? 4 Enter Option A (Start with * for correct answer) >> case Enter Option B (Start with * for correct answer) >> primitive Enter Option C (Start with * for correct answer) >> *type-wrapper Enter Option D (Start with * for correct answer) >> show How many points? 3 Please choose (c)reate a question, (p)review or (e)xit >> Enter the type of question (MC or TF) >> MC Enter the question text >> A(n) _ variable is known only within the boundaries of the method. How many options? 5 Enter Option A (Start with * for correct answer) >> method Enter Option B (Start with * for correct answer) >> *local Enter Option C (Start with * for correct answer) >> double Enter Option D (Start with * for correct answer) >> instance Enter Option E (Start with * for correct answer) >> global How many points? 2 Please choose (c)reate a question, (p)review or (e)xit >> Enter the type of question (MC or TF) >> TF Enter the question text >> Java is a free-form programming language. Answer is True or False? True How many points? 1 Please choose (c)reate a question, (p)review or (e)xit >> P Each primitive type in Java has a corresponding class contained in the java.lang package. These classes are called classes. (3.0 Points) A: case B: primitive C: type-wrapper D: show Enter your choice >> A You are wrong. The correct answer is C. A(n) variable is known only within the boundaries of the method. (2.0 Points) A: method B: local C: double D: instance E: global Enter your choice >> B You are correct! Java is a free-form programming language. (1.0 Points) True (T) or False (F) >> F You are wrong. The correct answer is true. The quiz ends. Your score is 2.0. Please choose (c)reate a question, (p)review or (e)xit >> Enter the type of question (MC or TF) >> MC Enter the question text >> A(n) constructor is one that requires no arguments. How many options? 3 Enter Option A (Start with * for correct answer) >> class Enter Option B (Start with * for correct answer) >> *default Enter Option C (Start with * for correct answer) >> explicit How many points? 2 Please choose (c)reate a question, (p)review or (e)xit >> Enter the type of question (MC or TF) >> TF Enter the question text >> Javascript and Java are the same. Answer is True or False? False How many points? 0.5 Please choose (c)reate a question, (p)review or (e)xit >> p Each primitive type in Java has a corresponding class contained in the java.lang package. These classes are called classes. (3.0 Points) A: case B: primitive C: type-wrapper D: show Enter your choice >> C You are correct! |A(n) variable is known only within the boundaries of the method. (2.0 Points) A: method B: local C: double D: instance E: global Enter your choice >> B You are correct! Java is a free-form programming language. (1.0 Points) True(T) or False(F) >> T You are correct! |A(n) constructor is one that requires no arguments. (2.0 Points) A: class B: default C: explicit Enter your choice >> C You are wrong. The correct answer is B. Javascript and Java are the same. (0.5 Points) True(T) or False(F) >> F You are wrong. The correct answer is false. The quiz ends. Your score is 6.5. Please choose (c)reate a question, (p)review or (e)xit >> e Goodbye! Requirement: 1. The output of the program MUST EXACTLY the same as the above sample run of in character level. 2. You must create classes according to the following class diagram (Note: italic font refers to abstract methods/classes, while normal font refers to concrete methods/classes): Question Text : String point: double Question() Question(String qText) EgetqText(): String setqText(String qText): void getPoint(): double setPoint(double point): void grade(String answer) : double getCorrect Answer(): String MCQuestion TFQuestion -answer:boolean options: ArrayList -answer : String -McQuestion() McQuestion(String qText, String options, double point) getOptions(): ArrayList setOptions(ArrayList options) : void -setOptions(String options): void -getAnswer(): String setAnswer(String answer) : void TFQuestion() -TFQuestion(String Text, boolean answer, double point) getAnswer(): boolean -setAnswer(String answer): void Question Class: - This class represents the generic form of question. It contains the question text (qText) and the point of a question (point). The grade method, which is an abstract method, has a parameter, answer (String). It returns the points of the question if the answer is correct, zero otherwise. The getCorrectAnswer method, which is an abstract method, has no parameter. It returns a String representing the correct answer to the question. MCQuestion Class - It is a subclass of Question. It represents a multiple-choice question. A multiple-choice question may have 3-5 options. Each element of the instance variable options refers to an option in this question. The instance variable answer is a single character string. It saves the correct answer ("A, B, "C", "D" or "E") to this question. The method setOptions (String options) has the answer field from the database (explained below) as the parameter. It will add all options to the instance variable options and set the instance variable answer. The constructor McQuestion(String qText, String options, double point) creates an MCQuestion object by setting the qText, adding option to options, setting the correctAnswer to answer and point by reading the QText, Answer, and Point fields from the database. TF Question Class - It is a subclass of Question. It presents a True/False question. The constructor TFQuestion(String qText, boolean answer, double point) creates an TFQuestion object by setting the qText, answer, and point by reading the qText, Answer, and Point fields from the database. 3. You must read/write from/to the database provided in this question (Question. accdb). This MS Access file contains a table called Questions. It contains the following fields: a. ID (Automatically generated integer by MCAccess) b. QText (Short Text): The question text c. Answer (Short Text): i. If this is a multiple-choice question, Answer stores all options separated by There is a leading **** for the correct option. ii. If this is a True/False question Answer stores the string "Ture" or "False". d. Point (Single): It is a float point number representing the point of this question. e. Type (Short Text): "MC" or "TF denoting multiple-choice or True/False questions respectively. 4. You must create a class Asgne3, which has the main method to run the program. 5. Refer to the following screenshots for the data format saved in the database. Wong, Ivan WI File Home Fields Table Tell me ab View Paste Question : Database- C:Temp\Question.accdb (Acces... Create External Data Database Tools Help 21 al Filter Refresh Find 2. Y All X Sort & Filter Records Find Questions ID QText Answer Point New) Text Formatting Views Clipboard All Ac... Search Tables ! Ques Type Click to Add- 0 No Hi Search Record 1 of 1 Datasheet View Figure 1: No records at the beginning

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

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

More Books

Students also viewed these Databases questions

Question

what is a peer Group? Importance?

Answered: 1 week ago