import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class CompAsstInst extends Applet
             implements ActionListener {
   
	Label prompt1;     
	TextField input1;  
	
	int Answer;
	int XPosition;  
	int YPosition = 70;
	int RandomArray[] = new int [2];
	int ArrayCounter = 0;
	int TotalEntered = 0;
	boolean AnsweredTheQuestion = false;
	boolean BadAnswer = false;
	String Question1;
	int TheAnswer;
  
   public void init()
   {
      prompt1 = new Label( "Enter an integer and press Enter" );
      add( prompt1 );  

      input1 = new TextField( 10 );
      input1.addActionListener( this );
      add( input1 );
	  
   }

   
   public void paint( Graphics g )
   {
	       
	      YPosition = 75;
		  XPosition = 25;
		  String TheCorrect;
		  String TheWrong;
	      int value;
		  if (AnsweredTheQuestion == false && BadAnswer == false)
		  {
			Question1 = new String ("How much is ");
			for (int aaaa = 0; aaaa <= RandomArray.length; aaaa++)
			{
					value = 1 + (int) (Math.random() * 9);
					RandomArray[aaaa] = value;
					if (aaaa == 0)
					{	
						Question1 = Question1.concat(String.valueOf(RandomArray[aaaa]));
						Question1 = Question1.concat("  *  ");
					}
					
					if (aaaa == 1)
					{
						
						Question1 = Question1.concat(String.valueOf(RandomArray[aaaa]));
						Question1 = Question1.concat("?");
					}
					
						
			      if (aaaa == 1)
					{
						TheAnswer = RandomArray[0] * RandomArray[1];
						g.drawString (Question1, XPosition, YPosition);
						YPosition += 15;
					}
				  
			} // end for loop
		  } // end if statement
		  
		  if (Answer == TheAnswer)
		  {
			  AnsweredTheQuestion = false;
			  BadAnswer = false;
			  TheCorrect = CorrectResponce();
			  g.drawString (TheCorrect, 80, 40);
		  }
		  else
		  {
			   BadAnswer = true;
			   AnsweredTheQuestion = false;
			   TheWrong = WrongResponce();
			   g.drawString (TheWrong, 80, 40);
			   g.drawString (Question1, 25, 75);
		  }  
		  
  } // end method
   
   
   public String WrongResponce()
   { 
	 int Responce;
	 String Wrong[] = {"No. Please try again.",
						"Wrong.  Try once more.",
						"Don't give up!",
						"No.  Keep trying."};
     Responce = (int) (Math.random() * 4);
	 return Wrong[Responce]; 
	
   }
   
    public String CorrectResponce()
   { 
	 int Responce;
	 String Correct[] = new String[4];
	 Correct[0] = "Very Good!";
     Correct[1] = "Excellent!";
     Correct[2] = "Nice Work!";
	 Correct[3] = "Keep up the good work!";
	 Responce = (int) (Math.random() * 4);
	 return Correct[Responce];
	 
	 
   }
  	   
   public void actionPerformed( ActionEvent e )
   {   
	  
      Answer = Integer.parseInt( input1.getText() );
	  input1.setText("");
	  AnsweredTheQuestion = true;
      repaint();
   }

}
