rendered paste body/*
*
*
**/
import javax.swing.*;
public class number17
{
public static void main(String[] args)
{
number17 x = new number17();
}
number17()
{
boolean playing = true;
int[] digits = {};
int guess;
do
{
digits = randomize();
JOptionPane.showMessageDialog(null, digits);
guess = Integer.parseInt(JOptionPane.showInputDialog(null, "What is your guess?"));
String foo = "";
for (int d=0;d<digits.length;d++)
{
foo += digits[d];
}
JOptionPane.showMessageDialog(null, /*giveHint(guess, digits)*/ foo );
playing = false;
}while (playing == true);
}
public int[] randomize()
{
int[] digits = {0,0,0};
for (int i=0; i<digits.length; i++)
{
digits[i] = (int) ((Math.random() * 9) + 1);
}
return digits;
}
public String giveHint(int userGuess, int[] checkingArray)
{
String totalHint = "";
String spot1Hint = "";
String spot2Hint = "";
String spot3Hint = "";
for (int i = 0; i<3; i++)
{
if (i==0)
{
if (userGuess == checkingArray[i])//dead on
{
spot1Hint = "Fermi";
}
else if(userGuess == checkingArray[i+1] || userGuess == checkingArray[i+2])//different position
{
spot1Hint = "Pico";
}
else if (userGuess != checkingArray[i] || userGuess != checkingArray[i+1] || userGuess != checkingArray[i+2])//none
{
spot1Hint = "Nano";
}
}
if (i==1)
{
if (userGuess == checkingArray[i])//dead on
{
spot2Hint = "Fermi";
}
if(userGuess == checkingArray[i-1] || userGuess == checkingArray[i+1])//different position
{
spot2Hint = "Pico";
}
if (userGuess != checkingArray[i] || userGuess != checkingArray[i-1] || userGuess != checkingArray[i+1])//none
{
spot2Hint = "Nano";
}
}
if (i==2)
{
if (userGuess == checkingArray[i])//dead on
{
spot3Hint = "Fermi";
}
if(userGuess == checkingArray[i-1] || userGuess == checkingArray[i-2])//different position
{
spot3Hint = "Pico";
}
if (userGuess != checkingArray[i] || userGuess != checkingArray[i-1] || userGuess != checkingArray[i-2])//none
{
spot3Hint = "Nano";
spot1Hint = "works";
}
}
}
totalHint = (spot1Hint + " " + spot2Hint + " " + spot3Hint);
return totalHint;
}
}