Site Loader

import java.util.Scanner;

public class Lab_2{

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

public static void main(String args) {
Scanner input = new Scanner(System.in);

String play = “y”;
do {

char word = getWord();

char space = new charword.length;
fill(space);

int missed = 0;
do {
char guess = getGuess(space);
if (!Check(word, space, guess))
missed++;

} while (!Finish(space));
print(word, missed);

System.out.println(“\nDo you want to guess another word? Enter y or n “);
play = input.next();

} while (play.charAt(0) == ‘y’);
}

public static char getWord() {
String words = {“write”, “that”, “program”, “mad”, “java”, “grant”,
“norris”, “crosscode”};

String Word = words(int) (Math.random() * words.length);
char letters = new charWord.length();

for (int i = 0; i < letters.length; i++) {
lettersi = Word.charAt(i);
}
return letters;
}

public static void fill(char list) {
for (int i = 0; i < list.length; i++) {
listi = '*';
}
}

public static boolean Check(char word, char blanks, char guess) {
boolean correct = false;
int missCheck = 2;
for (int i = 0; i 0)
print(missCheck, guess);
return correct;
}

public static boolean Finish(char blanks) {
for (int i = 0; i < blanks.length; i++) {
if (blanksi == '*')
return false;
}
return true;
}

public static void print(char word, int missed) {
System.out.print("The word is ");
System.out.print(word);
System.out.print(" you geussed wrong " + missed +" times");

}

public static void print(int check, char guess) {
if (check == 0) {
System.out.println(" is already in the word");
}
if (check ==1) {
System.out.println(" is not in the word");
}
}

public static char getGuess(char asterisks){
Scanner input = new Scanner(System.in);
System.out.print("Geuss a letter please ");
System.out.print(asterisks);
System.out.print( " Your Geuss: ");
String geuss = input.next();
return geuss.charAt(0);
}
}

Post Author: admin

x

Hi!
I'm Irma!

Would you like to get a custom essay? How about receiving a customized one?

Check it out