Sunday, December 22, 2019

Program Computer Programming - 867 Words

/*Name: James Keeling Assignment: Lab5 Program: computer programming user guesses what a randomly selected word is with 10 potential incorrect guesses*/ import java.util.Scanner; public class lab5 { public static void main(String[] args) { Scanner in = new Scanner(System.in); char c; String userContinue; System.out.println(Welcome to James Word Game!); //main game loop do{ //slection of words available for the game String[] words = new String[12]; words [0] = elation; words [1] = routine; words [2] = outlier; words [3] = outline;†¦show more content†¦nWord.length()]; int correctGuess = 0; for (int i = 0; i sessionWord.length(); i++) { unknown[i] = * ; } //loop for 1 game session //loop ends when correct number of guesses matches the session word //length or there are ten incorrect guesses while (correctGuess sessionWord.length() badGuess != 0) { //method that displays the number of * left to uncover //and asks for input input(badGuess, unknown, sessionWord); // get one character input from user char guess = in.next().toLowerCase().charAt(0); //initializes boolean matched as false boolean matched = false; //tests the user s guess this round against the session word //looking for matches if there is one correct guesses goes up 1 for (int i = 0; i sessionWord.length(); i++) { if ((guess == sessionWord.charAt(i)) (unknown[i] == * )) { unknown[i] = sessionWord.charAt(i); correctGuess++; matched = true; } } //if the input doesn t match the word their incorrect guess counter //goes down 1 if (!matched) badGuess--; } //method that displays a message depending i f

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.