100%(1)1 out of 1 people found this document helpful
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 2006Page 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 2006Page 9
System.out.println("Sunday");}}Client.javapackage 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 wordsHangman hangman2 = new Hangman("riffraff");Hangman hangman3 = new Hangman("Parabled");Scanner sc = new Scanner(System.in); // for taking input from userSystem.out.println("First round Begin!");System.out.println("We are playing Hangman");while (!hangman1.isFound()) { // for continuing till match not done completelySystem.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 characterSystem.out.println((guessResult > 0 ? "Correct" : "Incorrect") + ". Guessesmade "+ 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 2006Page 10
//if game completed another roundSystem.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 lengthSystem.out.println("Please enter single letter");input = sc.next();}int guessResult = hangman2.makeGuess(input.charAt(0));System.out.println((guessResult > 0 ? "Correct" : "Incorrect") + ". Guesses