How to create of Mastermind using loops in Java. INPUT: First, either a numeric
ID: 441719 • Letter: H
Question
How to create of Mastermind using loops in Java. INPUT: First, either a numeric code (like 3 5 6 2, for example) to guess or all 0s (like 0 0 0 0) for a random game. Then up to 10 guesses in the same format (like 4 6 2 4). OUTPUT: After each guess, the computer should report the white and red markers. At the end of the game, the winner/loser is announced, along with the solution. To play an online version of Mastermind that should look really close to what you're going to do, head here: http://stardock.cs.virginia.edu/miller/mastermind/ For more about the game, head to Wikipedia: http://en.wikipedia.org/wiki/Mastermind_(board_game) The output should look EXACTLY like this: Mastermind! Setup - Enter four integers (1-6) or four 0s for random: 4 4 5 5 Guess 1/10: 5 5 4 4 R: 0 W: 4 Guess 2/10: 5 4 4 5 R: 2 W: 2 Guess 3/10: 4 5 4 5 R: 2 W: 2 Guess 4/10: 4 4 5 6 R: 3 W: 0 Guess 5/10: 4 4 5 2 R: 3 W: 0 Guess 6/10: 4 4 4 4 R: 2 W: 0 Guess 7/10: 5 5 5 5 R: 2 W: 0 Guess 8/10: 8 8 8 8 R: 0 W: 0 Guess 9/10: 5 4 5 4 R: 2 W: 2 Guess 10/10: 5 5 4 5 R: 1 W: 2 Ans: 4 4 5 5 Game over! You lost!Explanation / Answer
public class JakobMastermind { public static void main(String[] args) { // INTRODUCTION System.out.println("Hi and welcome to the game Mastermind!! :) Made by Jakob Petersson "); // ANSWER/SECRET // (4 arrays for a combination of 4 numbers that will guess a number between 1 and 6) int[] secret=new int[4]; for(int i=0;i=1){ System.out.print("You have "+white+" white pins"); }else if(white==1 && black>=1){ System.out.print("You have "+white+" white pin"); }else if(white>1 && black==0){ System.out.println("You have "+white+" white pins."); }else if(white==1 && black==0){ System.out.println("You have "+white+" white pin."); } if(black>1 && white>=1){ System.out.println(" and "+black+" black pins."); }else if(black==1 && white>=1){ System.out.println(" and "+black+" black pin."); }else if(black==1 && white1 && whiteRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.