/* ***************************************************************************
   *   (c)Copyright notice - 2003 - Uwe "Ed" Beltz, JD.                      *
   *    All rights reserved.                                                 *
   *                                                                         *
   *    DISCLAIMER: The efforts including the development, research, and     *
   *  testing of the following program, and its effectiveness, are solely    *
   *  my effort in conjunction with training in INLS161 - Spring 2003.       *
   *  The author makes no warranty of any kind, expressed or implied,        *
   *  with regard to this, or any associated program.  The author shall not  *
   *  be held liable in any event for incidental or consequential damages    *
   *  arising in connection with, or arising out of, the use, furnishing,    *
   *  or performance of this program.                                        *
   *************************************************************************** */

import javax.swing.*;

public class SeatAssigner extends JApplet
{
    Seats flight = new Seats(); 
    //create an instance of Seats
    String seatNumber = "";     
    int section;                
    int newSection;             
    //needed variables
    
    public void init()
    {   
	//entire loop runs while seats are available
	while (flight.checkAll()) 
	{
	    section = Integer.parseInt(JOptionPane.showInputDialog(
			"Please enter 1 for \"smoking\"\n Please enter 2 \"nonsmoking\""));
	    //  Smoking Choice
	    if (section == 1) 
	    {
		//assigns a seat in smoking section if there is one available 
		if (flight.checkSmoking()) 
		{
		    seatNumber = flight.assignSmoking();
		    JOptionPane.showMessageDialog(null,
			"Seat Number: "+seatNumber+"\n Section: Smoking");
		}
		//if no avail. seat present options
		else
		{
		    newSection = Integer.parseInt(JOptionPane.showInputDialog(
				"All seats in smoking are full.\n"+
				"If you would like a seat in nonsmoking enter 1\n"+
				"If you would like to wait for the next flight enter 2"));
		    //assign seat in nonsmoking
		    if (newSection == 1) 
		    {
			if (flight.checkNon()) 
			{
			    seatNumber = flight.assignNon();
			    JOptionPane.showMessageDialog(null,
				"Seat Number: "+seatNumber+"\n Section: Nonsmoking");
			}
		    }
		    //present next flight message
		    else
		    {
			JOptionPane.showMessageDialog(null, "The next flight leaves in three hours.");
		    }
		}
	    }//end smoking conditional
	    
	    //for initial selection of nonsmoking
	    if (section == 2) 
	    {
		//assign seat in nonsmoking if available
		if (flight.checkNon()) 
		{
		    seatNumber = flight.assignNon();
		    JOptionPane.showMessageDialog(null,
			"Seat Number: "+seatNumber+"\n Section: Nonsmoking");
		}
		//if not, present options
		else
		{
		    newSection = Integer.parseInt(JOptionPane.showInputDialog(
				"All seats in nonsmoking are full.\n"+
				"If you would like a seat in smoking enter 1\n"+
				"If you would like to wait for the next flight enter 2"));
		    if (newSection == 1) 
		    {
			//assign seat in smoking
			if (flight.checkSmoking()) 
			{
			    seatNumber = flight.assignSmoking();
			    JOptionPane.showMessageDialog(null,
				"Seat Number: "+seatNumber+"\n Section: Smoking");
			}
		    }
		    //present next flight message
		    else
		    {
			JOptionPane.showMessageDialog(null, "The next flight leaves in three hours.");
		    }
		}
	    }//end nonsmoking conditional
	}//end while loop
	//display flight full message
	JOptionPane.showMessageDialog(null, "All seats on this flight are full");
    }
}

