JAVA 37
HangWord Guest on 3rd May 2021 03:20:57 PM
  1.  
  2. /**
  3.  * Write a description of class HangWord here.
  4.  *
  5.  * @author pblake
  6.  * @date 5/3/21
  7.  */
  8. public class HangWord
  9. {
  10.     private String word;
  11.     private int numGuesses;
  12.     private String hiddenForm;
  13.    
  14.     HangWord(String s)
  15.     {
  16.         word = s;
  17.         numGuesses = 0;
  18.         hiddenForm = "";
  19.         for(int i = 0; i < s.length(); i++)
  20.         {
  21.             hiddenForm += " _ ";
  22.         }
  23.     }
  24.    
  25.     public String getWord()
  26.     {
  27.         return this.word;
  28.     }
  29.    
  30.     public String getHiddenForm()
  31.     {
  32.         return this.hiddenForm;
  33.     }
  34.    
  35.     public String setHiddenForm(String s)
  36.     {
  37.         return this.hiddenForm = s;
  38.     }
  39.    
  40.     public boolean checkLetter(char c)
  41.     {
  42.         for(int i = 0; i < this.word.length(); i++)
  43.         {
  44.             if(this.word.charAt(i) == c)
  45.             {
  46.                 this.setHiddenForm(this.getHiddenForm().substring(0,i) +
  47.                                    c + this.getHiddenForm().substring(i + 1));
  48.                 return true;
  49.             }
  50.         }
  51.         return false;
  52.     }
  53.    
  54. }

Paste-bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.