import java.text.DecimalFormat;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class JExercise extends JApplet implements ActionListener 
{
	private static double exDay;
	private static double exTotal;
	private static String strEx;
	private static double avgEx;





	Container con = getContentPane();
	JLabel sunday = new JLabel("Enter minutes of exercise for Sunday");
	JLabel monday = new JLabel("Enter minutes of exercise for Monday");	
	JLabel tuesday = new JLabel("Enter minutes of exercise for Tuesday");
	JLabel wednesday = new JLabel("Enter minutes of exercise for Wednesday");
	JLabel thursday = new JLabel("Enter minutes of exercise for Thursday");
	JLabel friday = new JLabel("Enter minutes of exercise for Friday");
	JLabel saturday = new JLabel("Enter minutes of exercise for Saturday");
	JTextField sunAns = new JTextField(4);
	JTextField monAns = new JTextField(4);
	JTextField tueAns = new JTextField(4);
	JTextField wedAns = new JTextField(4);
	JTextField thuAns = new JTextField(4);
	JTextField friAns = new JTextField(4);
	JTextField satAns = new JTextField(4);
	JButton calculate = new JButton("Calculate Average");
	JLabel average = new JLabel("");
	

	// constructor
	public void init()
	{
		con.add(sunday);
		con.add(sunAns);
		con.add(monday);
		con.add(monAns);	
		con.add(tuesday);
		con.add(tueAns);	
		con.add(wednesday);
		con.add(wedAns);	
		con.add(thursday);
		con.add(thuAns);
		con.add(friday);
		con.add(friAns);		
		con.add(saturday);
		con.add(satAns);		
		con.add(calculate);
		
		con.add(average);		
		con.setLayout(new FlowLayout());

		calculate.addActionListener(this);
	}
	
	public void actionPerformed(ActionEvent e)
	{
		strEx = sunAns.getText();
		exDay = Double.parseDouble(strEx);
		exTotal = exTotal + exDay;
		strEx = monAns.getText();
		exDay = Double.parseDouble(strEx);
		exTotal = exTotal + exDay;	
		strEx = tueAns.getText();
		exDay = Double.parseDouble(strEx);
		exTotal = exTotal + exDay;		
		strEx = wedAns.getText();
		exDay = Double.parseDouble(strEx);
		exTotal = exTotal + exDay;
		strEx = thuAns.getText();
		exDay = Double.parseDouble(strEx);
		exTotal = exTotal + exDay;
		strEx = friAns.getText();
		exDay = Double.parseDouble(strEx);
		exTotal = exTotal + exDay;
		strEx = satAns.getText();
		exDay = Double.parseDouble(strEx);
		exTotal = exTotal + exDay;	
		
		avgEx = (exTotal / 60) / 7;
		if(exDay < 0 || exDay > 1440)
			throw(new LessThanZeroException());
		
		DecimalFormat df = new DecimalFormat("0.00");
		df.setMaximumFractionDigits(2);		
		average.setText("you have exercised an average of " + df.format(avgEx) + " hours per day.");
		validate();
		avgEx = 0;
		exTotal = 0;
		exDay = 0;
	}
}	
