// If_ElseDemo.java
// APPLET CODE="If_ElseDemo" HEIGHT=200 WIDTH=120
// Using nested if/else structures
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class If_ElseDemo extends JApplet implements ActionListener {
	int age, creditPeriod, discount;

	Container c;
	JLabel ageL, creditL, discL;
	JTextField inputAge, outputCredit, outputDisc;

	public void init( ) {
		c = getContentPane( );
		c.setLayout( new FlowLayout( ) );

		ageL = new JLabel( "Customer's age" );
		c.add( ageL );
		inputAge = new JTextField( 5 );
		inputAge.addActionListener( this );
		c.add( inputAge );
		creditL = new JLabel( "Credit Period" );
		c.add( creditL );
		outputCredit = new JTextField( 5 );
		outputCredit.setEditable( false );
		c.add( outputCredit );
		discL = new JLabel( "Discount" );
		c.add( discL );
		outputDisc = new JTextField( 5 );
		outputDisc.setEditable( false );
		c.add( outputDisc );
	}

	public void actionPerformed( ActionEvent e ) {
		age = Integer.parseInt( inputAge.getText( ) );
		
		// nested if/else structure
		if ( age >= 75 ) {
			creditPeriod = 90;
			discount = 15;
		} else if ( age >= 65 ) {
			creditPeriod = 60;
			discount = 10;
		} else {
			creditPeriod = 30;
			discount = 0;
		}
				
		outputCredit.setText( Integer.toString( creditPeriod ) );
		outputDisc.setText( Integer.toString( discount ) );
	}
}