//CAI.java
//Eric Tedjamulia
//10/31/03

//Tests student in Addition, subtraction, and multiplication.

import java.applet.Applet;
import java.awt.*;
import javax.swing.JOptionPane;

public class CAI extends Applet
{
		public void init()
		{
		calculate1 comp = new calculate1();
		
		//Declares Variables
		int choice = 0, num1, num2;
		String choice1;
		int again;
		
		//Game repeat
		do
		{
		int Score=0;
		
			//Gives choice of A,M, or S
			
			do
			{
				JOptionPane.showMessageDialog (null, "CAI: By Eric Tedj and Edward Tan");
				choice1 = JOptionPane.showInputDialog ("1) Addition 2) Subtraction 3) Multication");
				choice = Integer.parseInt(choice1);
				if (choice != 1 && choice != 2 && choice!=3)
					JOptionPane.showMessageDialog (null, choice + " is not a valid choice");		
			} 
			while (choice != 1 && choice != 2 && choice!=3);
			
			//repeats 10 times
			for (int i=0; i<10; i++)
			{
				num1 = (int)(Math.random()*10);
				num2 = (int)(Math.random()*10);
				if (choice == 1)
					Score+=(comp.add(num1,num2)*10);
				if (choice == 2)
					Score+=(comp.subtract(num1,num2)*10);
				if (choice == 3)
					Score+=(comp.multiply(num1,num2)*10);
			}
			
			comp.ScoreMsg(Score);
			
			//asks to play again
			again = JOptionPane.showConfirmDialog (null, "Play Again?");
		} while (again == JOptionPane.YES_OPTION);
		JOptionPane.showConfirmDialog (null, "Goodbye!");
		System.exit(0);
	}	
}
				 