Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Word Game A player (user) is playing a game of words with the computer. The computer repeatedly asks a question to the player whose answer

  1. Word Game

    A player (user) is playing a game of words with the computer. The computer repeatedly asks a question to the player whose answer consists of fixed and known number of letters (characters). The first question has an answer of 4 letters, the second has 5 and finally the last questions answer consists of exactly 6 letters. Each question has exactly one unique answer so that the players answers can be compared with the correct ones stored in the program as String arrays as will be explained later.

    When a question is presented to the screen, after seeing the question the player has two choices: either gives the answer or requests a letter of the answer. Example: Some possible scenarios for a question whose answer is table (having five letters). Question to be displayed to the player (with an answer of 5 letters):

    Scenario i:

    A furniture to sit around for eating or studying? Enter the answer 1 or request a letter 2: 1 ENTER table ENTER Correct! You gained 500 points.

    Scenario ii:

    A furniture sit around for eating or studying? Enter the answer 1 or request a letter 2: 1 ENTER chair ENTER Wrong! You lost 500 points.

    Scenario iii:

    A furniture sit around for eating or studying?

Enter the answer 1 or request a letter 2: 2 ENTER *a*** Enter the answer 1 or request a letter 2: 2 ENTER *ab**

Enter the answer 1 or request a letter 2: 1 ENTER table Correct! You gained 300 points.

Scenario iv:

A furniture sit around for eating or studying Enter the answer 1 or request a letter 2: 2 ENTER **b** Enter the answer 1 or request a letter 1: 1 ENTER board Wrong! You lost 400 points.

If the player gives an answer and it is correct, s/he will gain (letters- numberOfLettersRequested)*100 points. If the answer is wrong, s/he will lose (letters- numberOfLettersRequested)*100 points. Here, letter is the number of characters of the answer and numberOfLetersRequest is the total number of letters requested by the user before giving them the answer for this question.

In the above example letter is 5 (as the answer of the question has 5 letters world table). In scenario i at the first time without requesting a letter the user gives the correct answer (table). Hence, numberOfLettersRequest is 0 and s/he gains (5-0)*100 = 500 points (their accumulated points is increased by 500).

In scenario ii at the first time without requesting a letter the user gives the answer chair which is wrong, hence, (numberOfLettersReq is 0) s/he loses (5-0)*100 = 500 points (their accumulated pints is decreased by 500).

In scenario iii at the first time the user requests a letter (a randomly selected letter of table in this case its second letter a is presented *a***), hence, numberOfLettersReq becomes 1, then the player requests a letter again (a second letter of the correct answer - in this case the third letter b is presented together with the a *ab**). At this stage numberOfLettersReq becomes 2 after seeing *ab**; the user gives the correct answer and s/he gains (5-2)*100 = 300 points.

In scenario iv at the first time the user requests a letter (a randomly selected letter of table in this case its third letter b is presented **b**), hence, numberOfLettersReq is 1, then the user gives the answer but it is incorrect. So, numberOfLettersReq is still 1, and s/he loses (5-1)*100 = 400 points.

The player is asked 3 questions, whose answers consisting of letters ranging from 4 to 6 respectively and at the end of the game total score of the player is printed to the screen (if the player knows each question without asking any letter she gains 400+500+600 = 1500 points).

In your program there are three questions with answers having x letters (x ranging from 4 to 6). At each iteration a random selection is made from these three question. For example, when x = 5, there are three questions each represented as a String. All have answers with 5 letters say:

table, chair, flush, only one of which is randomly selected by the program and asked to the user as question whose answer is a world with 5 characters.

When the user requests a letter a randomly chosen letter from the answer is selected and the letter with its position is presented to the user. If a second letter is demanded, the first and the second and their positions are shown for the missing ones are shown as * character is displayed examples *a***,t*b**.

In your program represent questions and their corresponding answers as two distinct two- dimensional arrays of Strings. The ith index of the inner array represents ith question (whose answer has i+4 letters) and its correct answer, respectively. The jth element of the outer array is one of the three questions for a letter of i (and naturally their answers). Hold the answer of the player in a string and in deciding whether it is correct or not make a string comparison. Use Random or SecureRandom class nextInt method for generating random number.

After asking 3 questions whose answers are words from 4 to 6 letters, calculate and display overall score of the user to the screen.

This means you have to prepare 3*(6-4+1) = 3*3=9 questions answer pairs (3 questions whose answer is a 4 character world, 3 questions whose answer is a 5 character world and so on). Store these questions and answers as two dimensional String arrays. And for each character ranging from 4 to 6, ask only one of them to the player.

Use loops for iterating over questions from 4 to 6 as the number of questions asked might be increased in future versions of the game.

Define and initialize the String arrays (question and answer arrays) as class or field variables.

Use top down software development as much as possible. Preferentially your program should have methods other than main.

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_2

Step: 3

blur-text-image_3

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

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions