Hey guys, I'm currently at the very end of my java course this semester, and I was wondering if anyone could help me finish the last 3 of my 8 method in a program called Mastermind. The difference between typical Mastermind games and my assignment is that we're using numbers and not colors, and thats about it. The user has 12 guesses to break the 4 digit code, ranging in numbers from 1-6. I'm having problems with my checkAttempt, showResults, and playGame methods. Any help would be greatly appreciate. And I'd like to point out that I know very little about java, but I am willing to try to understand any help that comes my way.
Thanks for your time!
import java.util.Scanner;
import java.util.Random;
public class myname_Mastermind
{
private int[] code = new int[4];
private int[] [] board = new int [12][6];
private String name;
private int currentRow;
public myname_Mastermind ( String tempName ){
currentRow = 0;
name = tempName;
System.out.println ();
System.out.printf ( "Welcome to Mastermind, %s!\n\n", name );
System.out.println ( "You will try to guess a four-digit code that has been randomly
generated." );
System.out.println ( "The numbers you can use are between 1 and 6. I won't check to s
ee" );
System.out.println ( "if you only used those numbers however.\n" );
System.out.println ( "When you have a guess, enter four numbers separated by a space
in the" );
System.out.println ( "order you think I have them.\n" );
System.out.println ( "After each attempt, I will tell you how many numbers are in" );
System.out.println ( "the correct position and how many are present but in the wrong
position.\n" );
System.out.println ( "You have 12 attempts to guess my code. Good Luck!\n\n" );
System.out.println ( "------------------------------------------------" );
genCode();
}
public void genCode()
{
Random num = new Random ();
for ( int a = 0; a < 4 ; a++)
{
code[a] = num.nextInt(6) + 1;
public void getAttempt()
{ Scanner input = new Scanner(System.in);
currentRow++;
System.out.printf ("Enter 4 numbers for attempt #%d: ", currentRow);
board[0][0] = input.nextInt();
board[0][1] = input.nextInt();
board[0][2] = input.nextInt();
board[0][3] = input.nextInt();
}
public void showAttempts()
{
System.out.printf ("Results for attempt #%d:\n\n", currentRow);
System.out.printf ("Here are your previous guesses, %s\n\n", name);
System.out.printf ("Attempt %d: ", currentRow);
System.out.printf (board[0][0]+" ");
System.out.printf (board[0][1]+" ");
System.out.printf (board[0][2]+" ");
System.out.printf (board[0][3]+"\n");
}
public void checkAttempt() // hardest method
{
}
public void showResults ( int correct )
{
/** if ( board [0] == code [0] || board [1] == code [1] || board [2] == code [2] || board [3] == code [3] )
{
System.out.println ( "It looks like you won the game!" );
System.out.println ( " Congratulations!!!!" );
}
else
{
System.out.println ( "Sorry, it looks like you didn't win." );
}
*/
}
public void showCode(){
System.out.println ( "Here is the code:" );
System.out.printf ( " %d %d %d %d\n", code[0], code[1], code[2], code[3]);
System.out.println ();
}
/**
* This method runs the game for the user
* @param variable Brief description of variable.
* @return Brief description of return value here
*/
public void playGame()
{
}
}