Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java (1) Create variables to store a selection, username (one word), high score 1, 2 and 3, username for high score 1, 2, and 3,

Java

(1) Create variables to store a selection, username (one word), high score 1, 2 and 3, username for high score 1, 2, and 3, word (one word), user guess (single character), score, and number of incorrect guesses.

(2) Set the initial high scores to 0 and the initial usernames to the empty string.

(3) Display a menu as follows:

========================

MENU

------------------------

(S)tart new game

(D)isplay high scores

(Q)uit

========================

(4) Prompt and read a command from the user and perform the action.

Enter a command: s

(5) Start game will first set the score to 0, then ask the user for the word and the username and display the underscore character for each letter in the word (Hint: it might be easier to store this as a variable). It will then ask the user to enter a guess until they have guessed the entire word or until they have made 7 incorrect guesses. For each incorrect guess a part of the person should be displayed, and a point should be deducted from the score. For each correct guess, the letter should replace the underscore character at each location and a point should be added to the score.

Enter a command: s

Enter a word: fish

Enter a username: Riddler

____

Enter a guess: a

Incorrect guess.

O

____

Enter a guess: e

Incorrect guess.

O

|

____

Enter a guess: i

_i__

Enter a guess: b

Incorrect guess.

O

|

\\

_i__

Enter a guess: c

Incorrect guess.

O

|

\\ /

_i__

Enter a guess: d

Incorrect guess.

O

|

\\ /

|

_i__

Enter a guess: f

fi__

Enter a guess: n

Incorrect guess.

O

|

\\ /

|

/

fi__

Enter a guess: s

fis_

Enter a guess: t

Incorrect guess.

O

|

\\ /

|

/ \\

Sorry you lost.

(6) At the end of the game, if the user won 10 points should be added to their score. Regardless of if the user won or lost if the score is below 0 it should be set to zero. It should also update the high score list. The game should display their score at the end of the game and tell the user if they made the high score list.

Sorry you lost. Total score: 0

or

Congratulations! You won. Total score: 12

Congratulations you have the highest score.

or

Congratulations you have the 2nd highest score.

or

Congratulations you have the 3rd highest score.

(7) Display high scores will display the high score list in order.

========================

HIGH SCORES

------------------------

- 0

- 0

- 0

Example with three users:

HIGH SCORES

------------------------

Riddler - 10

Cat - 5

Mouse - 2

(8) Quit will tell the user that the program is terminated. All other commands should display an error.

Enter a command: q

Program terminated.

Enter a command: z

Error! Invalid command.

(9) Add a loop to the program so that the menu displays until the user selects the q command.

Enter a command: z

Error! Invalid command.

========================

MENU

------------------------

(S)tart new game

(D)isplay high scores

(Q)uit

========================

Enter a command: q

Program terminated.

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

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions