Consider a class that could be used to play a game of hangman. The class has the following attributes: - the secret word - the disguised word, in which each unknown letter is replaced with a question mark (?). For example, if the secret word is abracadabra and the letters a, b, and e have been guessed, the disguised word would be ab?a?a?ab?a. - the number of guesses made - the number of incorrect guesses It will have the following methods: - makeGuess(c) guesses that character c is in the word. - getDisguisedWord returns a string containing correctly guessed letters in their correct positions and unknown letters replaced with ?. - getSecretWord returns the secret word. - getGuessCount returns the number of guesses made. - isFound returns true if the hidden word has been discovered. a. write method heading for eeach method b. write preconditions and postconditions for each method c. write some java statements that test the class d. Implement the class.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Consider a class that could be used to play a game of hangman. The class
has the following attributes:
- the secret word
- the disguised word, in which each unknown letter is replaced with a question mark (?). For example, if the secret word is
abracadabra and the letters a, b, and e have been guessed, the disguised
word would be ab?a?a?ab?a.
- the number of guesses made
- the number of incorrect guesses
It will have the following methods:
- makeGuess(c) guesses that character c is in the word.
- getDisguisedWord returns a string containing correctly guessed letters in their correct positions and unknown letters replaced with ?.
- getSecretWord returns the secret word.
- getGuessCount returns the number of guesses made.
- isFound returns true if the hidden word has been discovered.

a. write method heading for eeach method
b. write preconditions and postconditions for each method
c. write some java statements that test the class
d. Implement the class.

2. Write an application that plays the game of Fermi. Generate three distinct
random digits between 0 and 9. These digits are assigned to positions 1, 2,
and 3. The goal of the game is for the player to guess the digits in three
positions correctly in the least number of tries. For each guess, the player
provides three digits for positions 1, 2, and 3. The program replies with a
hint consisting of Fermi, Pico, or Nano. If the digit guessed for a given
position is correct, then the reply is Fermi. If the digit guessed for a given
position is in a different position, the reply is Pico. If the digit guessed for a
given position does not match any of the three digits, then the reply is Nano.
Here are sample replies for the three secret digits 6, 5, and 8 at positions 1,
2, and 3, respectively:
Guess Hint Explanation
1 2 5 Nano Nano Pico The value 5 matches but
at the wrong position.
8 5 3 Pico Fermi Nano The value 5 matches at
the correct position. The
value 8 matches but at
the wrong position.
5 8 6 Pico Pico Pico All match at the wrong
positions.
Notice that if the hints like the above are given, the player can tell which
number did not match. For example, given the hint for the second guess, we
Exercises 435can tell that 3 is not one of the secret numbers. To avoid this, provide hints in
a random order or in alphabetical order (e.g., it will be Fermi Nano Pico
instead of Pico Fermi Nano for the second reply).
Play games repeatedly until the player wants to quit. After each game,
display the number of guesses made.

Consider a class that could be used to play a game of hangman. The class
has the following attributes:
• The secret word
The disguised word, in which each unknown letter in the secret word
has been replaced with a question mark (?). For example, if the secret
word is abracadabra and the letters a, b and e have been guessed, the
disguised word would be ab?a?a?a?ab?a.
• The number of guesses made.
• The number of incorrect guesses.
The class would have the following methods:
makeGuess (char c) guesses that character c is in the word.
getDisguisedWord() returns a String containing correctly guessed let-
ters in the correct positions and unknown letters replaced with ?.
getSecretWord() returns the secret word.
getGuessCount () returns the number of guesses made.
• isFound () returns true if the hidden word has been discovered.
Your task is to implement the class with the above variables and meth-
ods, then implement a "game" of hangman using this class. Your program
doens't need to draw anything.
Transcribed Image Text:Consider a class that could be used to play a game of hangman. The class has the following attributes: • The secret word The disguised word, in which each unknown letter in the secret word has been replaced with a question mark (?). For example, if the secret word is abracadabra and the letters a, b and e have been guessed, the disguised word would be ab?a?a?a?ab?a. • The number of guesses made. • The number of incorrect guesses. The class would have the following methods: makeGuess (char c) guesses that character c is in the word. getDisguisedWord() returns a String containing correctly guessed let- ters in the correct positions and unknown letters replaced with ?. getSecretWord() returns the secret word. getGuessCount () returns the number of guesses made. • isFound () returns true if the hidden word has been discovered. Your task is to implement the class with the above variables and meth- ods, then implement a "game" of hangman using this class. Your program doens't need to draw anything.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education