Assignment # 59 and Three Card Monte
Code
/// Name: Tommy Oyuntseren
/// Period: 7
/// Program Name: ThreeCardMonte
/// File Name: ThreeCardMonte.java
/// Date: 12/3/2015
import java.util.Scanner;
import java.util.Random;
public class ThreeCardMonte
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
byte guess = 0;
byte SN = (byte)(1 + r.nextInt(3));
System.out.println(" Welcome!!!\n Where is thew ball?\n");
System.out.println(" 1 2 3 ");
System.out.println(" | | | | | | ");
System.out.println(" / \\ / \\ / \\ ");
{
System.out.print("\nTry to guess it: ");
guess = (byte) keyboard.nextInt();
}
{
System.out.println();
System.out.println(" 1 2 3 ");
System.out.println(" | | | | | | ");
System.out.println(" / \\ / \\ / \\ ");
System.out.println(" "+((SN==1)?"O":"X")+" "+((SN==2)?"O":"X")+" "+((SN==3)?"O":"X"));
if(SN==guess) System.out.println("You guessed it! You must have cheated somehow!");
else System.out.println("Nope! The ball was in number "+SN);
System.out.println();
}
}
}
Picture of the output