/* CSCI 15A- 5 Assignment 3.2
 * 
 * Checkbox and calcutate total
 *
 * Author: Alex Chan October 14, 1998
 */

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class assig3q2 extends Applet implements ItemListener, ActionListener {

	TextField tTotal = new TextField(5);
	Label lTotal = new Label("Total Price ");
	CheckboxGroup sandwich = new CheckboxGroup();
	Checkbox ChickenS = new Checkbox("Chicken Sandwich ($3.00)", sandwich, true),
			 TurkeyS = new Checkbox("Turkey Sandwich ($2.50)", sandwich, false),
			 BeefS = new Checkbox("Beef Sandwich ($2.75)", sandwich, false),
			 Soda = new Checkbox("Soda ($0.75)", false),
			 Tomato = new Checkbox("Tomato ($0.50)", false),
			 Onion = new Checkbox("Onion ($0.50)", false),
			 Pickle = new Checkbox("Pickle ($0.50)", false);
	Button okButton;
	final double ChickenPrice = 3.0, TurkeyPrice = 2.5, BeefPrice = 2.75, 
				 SodaPrice = .75, TomatoPrice = .5, OnionPrice =.5, PicklePrice = .5;
	double SandwichPrice, TotalPrice;
	boolean bSoda, bTomato, bOnion, bPickle;
	
public void init() {
	
	add(ChickenS);
	add(TurkeyS);
	add(BeefS);
	add(Soda);
	add(Tomato);
	add(Onion);
	add(Pickle);
	okButton = new Button("OK");
	add(okButton);
	add(lTotal);
	add(tTotal);
	
	ChickenS.addItemListener(this);
	TurkeyS.addItemListener(this);
	BeefS.addItemListener(this);
	Soda.addItemListener(this);
	Tomato.addItemListener(this);
	Onion.addItemListener(this);
	Pickle.addItemListener(this);
	okButton.addActionListener(this);
 }

public void itemStateChanged (ItemEvent e) {
	
	if (e.getSource() == TurkeyS)
		SandwichPrice = TurkeyPrice;
	else if (e.getSource() == BeefS)
		SandwichPrice = BeefPrice;
	else SandwichPrice = ChickenPrice;
	
	TotalPrice = 0;
	if (e.getSource() == Soda)
		bSoda = true;
	if (e.getSource() == Onion)
		bOnion = true;
 	if (e.getSource() == Pickle)
		bPickle = true;
	if (e.getSource() == Tomato)
		bTomato = true;
	
	if (bSoda)
		TotalPrice += SodaPrice;
	if (bOnion)
		TotalPrice += OnionPrice;
	if (bPickle)
		TotalPrice += PicklePrice;
	if (bTomato)
		TotalPrice += TomatoPrice;
		
	TotalPrice += SandwichPrice;		
} 

public void actionPerformed (ActionEvent e) {

	tTotal.setText("$" + TotalPrice);
}

}	
	
			 
			 	 
