Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Quiz application that asks the user questions, prompts for a response and then compares the response to an answer. An incorrect answer will

Create a Quiz application that asks the user questions, prompts for a response and then compares the response to an answer. An incorrect answer will display the correct answer, a correct answer should respond with an affirmation.

Create a new project called Quiz.

Create a new class called Quiz.

In the main method for the Quiz class, create a Map object that will hold questions and answers. I suggest a HashMap.

The keys of the Map, the questions, will be type String.

The values of the Map, the answers, will be type String.

Populate the Map with some questions and answers, using the put() method. Feel free to be creative. There should be at least four questions; no more than about ten.

Using the keySet() method, create a Set of questions.

Using either a foreach loop or an Iterator, loop over all of the questions. Note: The foreach loop will require the use of Generics. The Generic for a HashMap with Strings for the key and value is .

Print the question from the keySet to standard out.

Prompt for input from the user. Use a Scanner or JOptionPane to accept the user's input.

Get the answer from the Map using the keySet value and the get() method on the Map.

Compare the user input to the Map's answer using the equalsIgnoreCase() method on the answer String. I also used the trim method on the answer and the user's input.

On an incorrect answer, print the correct answer.

On a correct answer print an affirmation, like "Correct." or "Right answer!"

As required for all assignments from now on

validate the proper functionality using the example answers below and review the Concepts and Ideas checklist format the code

add a comment at the top of the file that reads @ author and your name

build the javadocs

Verify that the jar file contains source and class files and the MANIFEST.MF file contains a Main-Class. See the Resources section for Configuring Eclipse to view Jar files.

Run the application from the jar file, either from the command line using java -jar jarfilename or from Eclipse. See the Resources section for Configuring Eclipse to run Jar files.

submit the jar file in the Assignment section of BlackBoard under View/Complete Assignment for this assignment.

Example:

Bridge Keeper: Stop! Who would cross the Bridge of Death must answer me these questions 3 (no 5), 'ere the other side he see.

Sir Galahad of Camelot: Ask me the questions, bridge-keeper. I'm not afraid.

Bridge Keeper: What is your quest?

Sir Galahad of Camelot: To seek the Holy Grail

Correct

Bridge Keeper: What is your name?

Sir Galahad of Camelot: Sir Galahad of Camelot

Correct

Bridge Keeper: What is the airspeed velocity of an unladen swallow?

Sir Galahad of Camelot: African or European?

Incorrect. The correct answer is 11 meters per second, or 24 miles an hour

(http://www.style.org/unladenswallow/)

Bridge Keeper: What is your favorite color?

Sir Galahad of Camelot: Blue. No yel-- Auuuuuuuugh!

Correct

Bridge Keeper: What is the Capital of Assyria?

Sir Galahad of Camelot: I don't know

Incorrect. The correct answer is Ashur (or Qalat Sherqat), Calah (or Nimrud), the short-lived Dur Sharrukin (or Khorsabad), or Nineveh

3 of 5 questions were answered correctly.

You missed 2 so you may not cross the bridge.

Off you go then.

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

Build It For The Real World A Database Workbook

Authors: Wilson, Susan, Hoferek, Mary J.

1st Edition

0073197599, 9780073197593

More Books

Students also viewed these Databases questions