package colorguesser;
import javax.swing.JOptionPane;
/**
*
* @author Jesse
*/
public class ColorGuesser {
private static int num;
public static void main(String[] args) {
int a = JOptionPane.YES_OPTION;
int b = JOptionPane.YES_OPTION;
int c = JOptionPane.YES_OPTION;
int right=0, wrong=0, tries=0;
while (a == JOptionPane.YES_OPTION ) {
Object[] Choice = {"Red", "Green", "Blue", "Yellow"};
String R = (String)JOptionPane.showInputDialog(
null,
"What is your first choice: \n",
"Your Choice",
JOptionPane.PLAIN_MESSAGE,
null,
Choice,
"Red");
Object[] Choice2 = {"Red", "Green", "Blue", "Yellow"};
String B = (String)JOptionPane.showInputDialog(
null,
"What is your second choice: \n",
"Your Choice",
JOptionPane.PLAIN_MESSAGE,
null,
Choice2,
"Red");
Object[] Choice3 = {"Red", "Green", "Blue", "Yellow"};
String G = (String)JOptionPane.showInputDialog(
null,
"What is your third choice: \n",
"Your Choice",
JOptionPane.PLAIN_MESSAGE,
null,
Choice3,
"Red");
tries = tries+1;
System.out.println("\nYou are on try: " + tries + "\n");
if ("Red".equals(R)) {
num = (int) (Math.random()*4+1);
if (num==1) {
right = right+1;
System.out.println("You picked Red and the computer had also picked Red! (Right)");
}
if (num==2) {
wrong = wrong+1;
System.out.println("You picked Red and the computer had picked Green! (Wrong)");
}
if (num==3) {
wrong = wrong+1;
System.out.println("You picked Red and the computer had picked Blue! (Wrong)");
}
if (num==4) {
wrong = wrong+1;
System.out.println("You picked Red and the computer had picked Yellow! (Wrong)");
}
}
if ("Green".equals(R)) {
num = (int) (Math.random()*4+1);
if (num==1) {
wrong = wrong+1;
System.out.println("You picked Green and the computer had picked Red! (Lose)");
}
if (num==2) {
right = right+1;
System.out.println("You picked Green and the computer had also picked Green! (Win)");
}
if (num==3) {
wrong = wrong+1;
System.out.println("You picked Green and the computer had picked Blue! (Lose)");
}
if (num==4) {
wrong = wrong+1;
System.out.println("You picked Green and the computer had picked Yellow! (Lose)");
}
}
if ("Blue".equals(R)) {
num = (int) (Math.random()*4+1);
if (num==1) {
wrong = wrong+1;
System.out.println("You picked Blue and the computer had picked Red! (lose)");
}
if (num==2) {
wrong = wrong+1;
System.out.println("You picked Blue and the computer had picked Green! (Lose)");
}
if (num==3) {
right = right+1;
System.out.println("You picked Blue and the computer had also picked Blue! (Win)");
}
if (num==4) {
wrong = wrong+1;
System.out.println("You picked Blue and the computer had picked Yellow! (Lose)");
}
}
if ("Yellow".equals(R)) {
num = (int) (Math.random()*4+1);
if (num==1) {
wrong = wrong+1;
System.out.println("You picked Yellow and the computer had picked Red! (Lose)");
}
if (num==2) {
wrong = wrong+1;
System.out.println("You picked Yellow and the computer had picked Green! (Lose)");
}
if (num==3) {
wrong = wrong+1;
System.out.println("You picked Yellow and the computer had picked Blue! (Lose)");
}
if (num==4) {
right = right+1;
System.out.println("You picked Yellow and the computer had also picked Yellow! (Win)");
}
}
if ("Red".equals(B)) {
num = (int) (Math.random()*4+1);
if (num==1) {
right = right+1;
System.out.println("You picked Red and the computer had also picked Red! (Right)");
}
if (num==2) {
wrong = wrong+1;
System.out.println("You picked Red and the computer had picked Green! (Wrong)");
}
if (num==3) {
wrong = wrong+1;
System.out.println("You picked Red and the computer had picked Blue! (Wrong)");
}
if (num==4) {
wrong = wrong+1;
System.out.println("You picked Red and the computer had picked Yellow! (Wrong)");
}
}
if ("Green".equals(B)) {
num = (int) (Math.random()*4+1);
if (num==1) {
wrong = wrong+1;
System.out.println("You picked Green and the computer had picked Red! (Wrong)");
}
if (num==2) {
right = right+1;
System.out.println("You picked Green and the computer had also picked Green! (Right)");
}
if (num==3) {
wrong = wrong+1;
System.out.println("You picked Green and the computer had picked Blue! (Wrong)");
}
if (num==4) {
wrong = wrong+1;
System.out.println("You picked Green and the computer had picked Yellow! (Wrong)");
}
}
if ("Blue".equals(B)) {
num = (int) (Math.random()*4+1);
if (num==1) {
wrong = wrong+1;
System.out.println("You picked Blue and the computer had picked Red! (Wrong)");
}
if (num==2) {
wrong = wrong+1;
System.out.println("You picked Blue and the computer had picked Green! (Wrong)");
}
if (num==3) {
right = right+1;
System.out.println("You picked Blue and the computer had also picked Blue! (Right)");
}
if (num==4) {
wrong = wrong+1;
System.out.println("You picked Blue and the computer had picked Yellow! (Wrong)");
}
}
if ("Yellow".equals(B)) {
num = (int) (Math.random()*4+1);
if (num==1) {
wrong = wrong+1;
System.out.println("You picked Yellow and the computer had picked Red! (Wrong)");
}
if (num==2) {
wrong = wrong+1;
System.out.println("You picked Yellow and the computer had picked Green! (Wrong)");
}
if (num==3) {
wrong = wrong+1;
System.out.println("You picked Yellow and the computer had picked Blue! (Wrong)");
}
if (num==4) {
right = right+1;
System.out.println("You picked Yellow and the computer had also picked Yellow! (Right)");
}
}
if ("Red".equals(G)) {
num = (int) (Math.random()*4+1);
if (num==1) {
right = right+1;
System.out.println("You picked Red and the computer had also picked Red! (Right)"
+ "\nRight - " + right + "\nWrong - " + wrong);
}
if (num==2) {
wrong = wrong+1;
System.out.println("You picked Red and the computer had picked Green! (Wrong)"
+ "\nRight - " + right + "\nWrong - " + wrong);
}
if (num==3) {
wrong = wrong+1;
System.out.println("You picked Red and the computer had picked Blue! (Wrong)"
+ "\nRight - " + right + "\nWrong - " + wrong);
}
if (num==4) {
wrong = wrong+1;
System.out.println("You picked Red and the computer had picked Yellow! (Wrong)"
+ "\nRight - " + right + "\nWrong - " + wrong);
}
}
if ("Green".equals(G)) {
num = (int) (Math.random()*4+1);
if (num==1) {
wrong = wrong+1;
System.out.println("You picked Green and the computer had picked Red! (Wrong)"
+ "\nRight - " + right + "\nWrong - " + wrong);
}
if (num==2) {
right = right+1;
System.out.println("You picked Green and the computer had also picked Green! (Right)"
+ "\nRight - " + right + "\nWrong - " + wrong);
}
if (num==3) {
wrong = wrong+1;
System.out.println("You picked Green and the computer had picked Blue! (Wrong)"
+ "\nRight - " + right + "\nWrong - " + wrong);
}
if (num==4) {
wrong = wrong+1;
System.out.println("You picked Green and the computer had picked Yellow! (Wrong)"
+ "\nRight - " + right + "\nWrong - " + wrong);
}
}
if ("Blue".equals(G)) {
num = (int) (Math.random()*4+1);
if (num==1) {
wrong = wrong+1;
System.out.println("You picked Blue and the computer had picked Red! (Wrong)"
+ "\nRight - " + right + "\nWrong - " + wrong);
}
if (num==2) {
wrong = wrong+1;
System.out.println("You picked Blue and the computer had picked Green! (Wrong)"
+ "\nRight - " + right + "\nWrong - " + wrong);
}
if (num==3) {
right = right+1;
System.out.println("You picked Blue and the computer had also picked Blue! (Right)"
+ "\nRight - " + right + "\nWrong - " + wrong);
}
if (num==4) {
wrong = wrong+1;
System.out.println("You picked Blue and the computer had picked Yellow! (Wrong)"
+ "\nRight - " + right + "\nWrong - " + wrong);
}
}
if ("Yellow".equals(G)) {
num = (int) (Math.random()*4+1);
if (num==1) {
wrong = wrong+1;
System.out.println("You picked Yellow and the computer had picked Red! (Wrong)"
+ "\nRight - " + right + "\nWrong - " + wrong);
}
if (num==2) {
wrong = wrong+1;
System.out.println("You picked Yellow and the computer had picked Green! (Wrong)"
+ "\nRight - " + right + "\nWrong - " + wrong);
}
if (num==3) {
wrong = wrong+1;
System.out.println("You picked Yellow and the computer had picked Blue! (Wrong)"
+ "\nRight - " + right + "\nWrong - " + wrong);
}
if (num==4) {
right = right+1;
System.out.println("You picked Yellow and the computer had also picked Yellow! (Right)"
+ "\nRight - " + right + "\nWrong - " + wrong);
}
}
Object[] options = {"Yes",
"No"};
a = JOptionPane.showConfirmDialog(null,
"Would you like to play again?",
"A question",
JOptionPane.YES_NO_OPTION);
if (a == JOptionPane.NO_OPTION) {
System.out.println("You have opted to not play again. Have a nice day.");
System.exit(0);
}
}
}
}