// program to calculate the exam marks of three subjects
// Author Chris IOAKIM
// dated 12/01/02

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

//Use of Action listener fore receiving actions events
//When the action event happens , the objects ActionPerformed method is evoked

public class ExamM1 extends Applet implements ActionListener
{
	private TextField maths;
	private TextField english;
	private TextField history;
	private TextField result;
	private TextArea average;
	private Label label1;
	private Label label2;
	private Label label3;
	private Font font;
	private Button calculate;
	private Button clear;
	
	// method call by the browser or appletviewer 
	//when an Applet is going to be executed 
	
	public void init()
	{
		// set the textfields and textarea
		
		maths = new TextField(3);
		english = new TextField(3);
		history = new TextField(3);
		result = new TextField(6);
		average = new TextArea(4,25);
		
		// set the font
		font = new Font("TimesRoman",Font.BOLD,14);
		
		// set the labels
		
		label1 = new Label();
		label1.setText("Maths");
		label1.setFont(font);
		
		label2 = new Label();
		label2.setText("English");
		label2.setFont(font);
		
		label3 = new Label();
		label3.setText("History");
		label3.setFont(font);
		
		// set up the buttons
		
		calculate = new Button("Calculate");
		calculate.addActionListener(this);
		
		clear = new Button("Clear");
		clear.addActionListener(this);
		
		//add TextField textAreas and buttons to applet
		
		add(label1);
		add(maths);
		add(label2);
		add(english);
		add(label3);
		add(history);
		add(average);
		add(result);
		add(calculate);
		add(clear);
		
	}
	
	public void actionPerformed(ActionEvent e)
	{
		// checks if the button is pressed
		if (e.getSource()==calculate)
		{
			int Maths,English,History,sum;
			double Average;
			String Result;
			String s;
			
			s = maths.getText(); // reads in the maths box
			Maths = Integer.parseInt(s); // converts it to an int
			
			s = english.getText();
			English = Integer.parseInt(s);
			
			s = history.getText();
			History = Integer.parseInt(s);
			
			sum = Maths + English + History;
			Average = sum/3;
			
			s=Double.toString(Average);
			average.setText(s);
			
			if (Average<70)
			{
				result.setText("Fail");
			}
			else 
			{
				result.setText("Pass");
			}
		}
	
		if (e.getSource()==clear)
		{
			maths.setText("");
			english.setText("");
			history.setText("");
			average.setText("");
			result.setText("");
		}				
	}
} // ends class		