// Calculate2.java
// Eric Tedjamulia
// 10-31-03

// Computer Aided Instruction Class

import java.applet.Applet;
import java.awt.*;
import javax.swing.JOptionPane;

public class calculate1
{
	private int num1;
	private int num2;
	private int compRes;
	private int usrRes;
	private int Score;
	private String inNum;
		
	public calculate1() { }
	
	public int add(int n1, int n2)
	{
		num1 = n1;
		num2 = n2;
		compRes = num1 + num2;
		for (int i=3; i>0; i--)
		{
			inNum = JOptionPane.showInputDialog (num1 + " + " + num2+" = ");
			usrRes = Integer.parseInt(inNum);
			if (usrRes == compRes)
				return (1);
			else
				JOptionPane.showMessageDialog (null,"Incorrect: " + (i-1) + " guess left.");
		}
		return (0);	
	}

	public int subtract(int n1, int n2)
	{
		num1 = n1;
		num2 = n2;
		compRes = num1 - num2;
		for (int i=3; i>0; i--)
		{
			inNum = JOptionPane.showInputDialog (num1 + " - " + num2+" = ");
			usrRes = Integer.parseInt(inNum);
			if (usrRes == compRes)
				return (1);
			else
				JOptionPane.showMessageDialog (null, "Incorrect: " + (i-1) + " guess left.");
		}
		return (0);	
	}

	public int multiply(int n1, int n2)
	{
		num1 = n1;
		num2 = n2;
		compRes = num1 * num2;
		for (int i=3; i>0; i--)
		{
			inNum = JOptionPane.showInputDialog (num1 + " * " + num2+" = ");
			usrRes = Integer.parseInt(inNum);
			if (usrRes == compRes)
				return (1);
			else
				JOptionPane.showMessageDialog (null,"Incorrect: " + (i-1) + " guess left.");
		}
		return (0);	
	}
	
	public void ScoreMsg(int score)
	{
		Score = score;
		JOptionPane.showMessageDialog (null, "Your Score is " + Score);
		if (Score>70)
			JOptionPane.showMessageDialog (null,"Keep up the good work!");
		else
			JOptionPane.showMessageDialog (null,"You need to work more on this.");
	}
}			