Status: Started
  • HiddenWord.java
  • HiddenWordTester.java
Font Size
14
Parentheses autocomplete
Wrap lines
Editor
Theme
Code with blocks by default
Console Font Size
12
Console Theme
Display Server Graphics Screen
Show File Tab Bar
Debug Mode
3 Hidden Word Complete Class (run code)
HiddenWordTester.java
public class HiddenWordTester
{
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Output
Grading
Docs
Exercise
More
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Pass Test Message

Errors:

This student is viewing this assignment in English. View this page in English?

5 points

Consider a guessing game in which a player tries to guess a hidden word. The hidden word contains only capital letters and has a length known to the player. A guess contains only capital letters and has the same length as the hidden word.


After a guess is made, the player is given a hint that is based on a comparison between the hidden word and the guess. Each position in the hint contains a character that corresponds to the letter in the same position in the guess. The following rules determine the characters that appear in the hint.


If the letter in the guess is ... the corresponding character in the hint is:

  1. also in the same position in the hidden word ... the matching letter
  2. also in the hidden word, but in a different position ... "+"
  3. not in the hidden word ... "*"


The HiddenWord class will be used to represent the hidden word in the game. The hidden word is passed to the constructor. The class contains a method, getHint, that takes a guess and produces a hint.


For example, suppose the variable puzzle is declared as follows.


HiddenWord puzzle = new HiddenWord("HARPS");


The following table shows several guesses and the hints that would be produced.


Call to getHint --> String returned

  1. puzzle.getHint("AAAAA") --> "+A+++"
  2. puzzle.getHint("HELLO") --> "H****"
  3. puzzle.getHint("HEART") --> "H*++*"
  4. puzzle.getHint("HARMS") --> "HAR*S"
  5. puzzle.getHint("HARPS") --> "HARPS"


Write the complete HiddenWord class, including any necessary instance variables, its constructor, and the method, getHint, described above. You may assume that the length of the guess is the same as the length of the hidden word. 

Reset Code

Slides and Notes

No slides available for this video

About

Java (main)
Java Version 1.8.0_222