You are on page 1of 2

import java.util.

*;
abstract interface I{
}
abstract interface N{
}
abstract interface T{
}
public class Main implements N, I, T
{
public static void main(String[] args) {
System.out.println("Let’s play a game called \"Odds or Evens\"");

Scanner del = new Scanner(System.in);

System.out.print("What is your name? ");


String name = del.nextLine();

System.out.print("Hi " + name + ", which do you choose? (O)dds or (E)vens?


");
String choice = del.next();

boolean choiceFlag;
choiceFlag = false;
do {
if (choice.equals("O")) {
System.out.println(name + " has picked odds! The Program will be
evens.");
choiceFlag = true;
} else if (choice.equals("E")) {
System.out.println(name + " has picked evens! The Program will be
odds.");
choiceFlag = true;
} else {
do {
System.out.println(name + "! you have made wrong choice.");
System.out.print("Choose either O or E, which one do you like?
");
choice = del.next();
if(choice.equals("O") || choice.equals("E"))
break;
} while (!(choice.equals("E")));
}
} while( choiceFlag == false);
System.out.println("--------------------------------------------------");
System.out.println();

System.out.print("How many \"finger(s)\" do you put out? ");


int userNumber = del.nextInt();

Random rand = new Random();


int computerNumber = rand.nextInt(6);

boolean flag;
flag = false;
do {
if(choice.equals("E") && userNumber % 2 == 0){
if( computerNumber % 2 != 0)
flag = true;
else if(computerNumber % 2 == 0)
{
do{
computerNumber = rand.nextInt(6);
}while( computerNumber % 2 == 0 );
}
}
else if(choice.equals("O") && userNumber % 2 != 0){
if( computerNumber % 2 == 0)
flag = true;
else if(computerNumber % 2 != 0)
{
do{
computerNumber = rand.nextInt(6);
}while( computerNumber % 2 != 0 );
}
}
else {
flag = false;
System.out.print("Choose \"fingers\" according to selected \"" +
choice + "\" choice: ");
userNumber = del.nextInt();
}
} while (flag == false);

System.out.println("The computer plays " + computerNumber +


" \"finger(s)\".");
System.out.println("--------------------------------------------------");
System.out.println();

int sum = userNumber + computerNumber;


System.out.println( userNumber + "+" + computerNumber + " = " + sum);
if( sum % 2 == 0 ) {
System.out.println( sum + " is ...even!");

if( userNumber % 2 == 0)
System.out.println("That means " + name + " wins!");
else
System.out.println("That means computer wins!");
}
else{
System.out.println( sum + " is ...odd!");

if( userNumber % 2 != 0)
System.out.println("That means " + name + " wins!");
else
System.out.println("That means computer wins!");
}
System.out.println("--------------------------------------------------");
System.out.println();
}
}

You might also like