int noofoccurence0 thisnoofguess

Int noofoccurence0 thisnoofguess

This preview shows page 8 - 12 out of 12 pages.

int no_of_occurence=0 ; this.no_of_guess++ ; if(this.secret_word.toLowerCase().contains(String.valueOf(ch).toLowerCase())){ for(int i=0;i<this.disguised_word.length();i++){ if(this.secret_word.toLowerCase().charAt(i)==ch){ this.disguised_word =this.disguised_word.substring(0, i) +ch+this.disguised_word.substring(i+1) ; no_of_occurence++ ; } } }else{ this.no_of_incorrect_guess++; } return no_of_occurence ; } /* Electronic Assignment Submission and Marking Working Party - Final Report to Academic Council 17 May 2006 Page 8
Image of page 8
For preparing the disguised string from the given secret word */ public Hangman(String secret_word) { this.secret_word = secret_word; this.disguised_word="" ; for(int i=0;i<this.secret_word.length();i++){ this.disguised_word+="?" ; } } /* For getting the disguised phrase value */ public String getDisguisedWord(){ return this.disguised_word ; } /* For getting the secret word value */ public String getSecretWord(){ return this.secret_word ; } /* For getting the no of guesses made count */ public int getGuessCount(){ return this.no_of_guess ; } /* For verifying the strings to check whether it is matched completely or not */ public boolean isFound(){ return this.disguised_word.equals(this.secret_word) ; } /* For getting the wrong guesses count */ public int getWrongGuessCount(){ return this.no_of_incorrect_guess ; } public static void StudentInfo(){ System.out.println("Haider"); System.out.println("33595746"); System.out.println("Internal"); Electronic Assignment Submission and Marking Working Party - Final Report to Academic Council 17 May 2006 Page 9
Image of page 9
System.out.println("Sunday"); } } Client.java package hangman; import java.util.Scanner; public class Client { public static void main(String[] args) { Hangman.StudentInfo(); String input = ""; Hangman hangman1 = new Hangman("behooves"); //Assign the secret words Hangman hangman2 = new Hangman("riffraff"); Hangman hangman3 = new Hangman("Parabled"); Scanner sc = new Scanner(System.in); // for taking input from user System.out.println("First round Begin!"); System.out.println("We are playing Hangman"); while (!hangman1.isFound()) { // for continuing till match not done completely System.out.println("The disguised word is : < " + hangman1.getDisguisedWord() + " >"); System.out.println("Please guess a letter to play"); input = sc.next(); while (input.length() != 1) { System.out.println("Please enter single letter"); input = sc.next(); } int guessResult = hangman1.makeGuess(input.charAt(0)); // matching the character System.out.println((guessResult > 0 ? "Correct" : "Incorrect") + ". Guesses made " + hangman1.getGuessCount() + " with " + hangman1.getWrongGuessCount() + " wrong"); } System.out.println("Congratulations, you found the secret word: " + hangman1.getSecretWord()); System.out.println("************************************************* ***************"); Electronic Assignment Submission and Marking Working Party - Final Report to Academic Council 17 May 2006 Page 10
Image of page 10
//if game completed another round System.out.println("Almost... Second round Begin!"); System.out.println("We are playing hangman"); while (!hangman2.isFound()) { System.out.println("Here is the disguised word " + hangman2.getDisguisedWord()); System.out.println("Please guess a letter to play"); input = sc.next(); while (input.length() != 1) { // for comparing input length System.out.println("Please enter single letter"); input = sc.next(); } int guessResult = hangman2.makeGuess(input.charAt(0)); System.out.println((guessResult > 0 ? "Correct" : "Incorrect") + ". Guesses
Image of page 11
Image of page 12

You've reached the end of your free preview.

Want to read all 12 pages?

  • Summer '19
  • Letter case, Lower case, Haider

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture