

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


2 Chris Parks 3 CSCI 2350 4 2/12/ 5 Airline.java 6 To create a reservation system for a new airline with a 10 seated plane. Create a boolean 7 array that has the first 5 spaces open for a smoking section and the second 5 spaces 8 open for a non-smoking section. If one section is full ask if the passenger would like 9 to be put in the other section. When the array is full, all members are true, then the 10 plane is empty. 11 / 12 import javax.swing.; 13 import java.awt.; 14 import java.awt.event.; 15 16 public class Airline extends JApplet implements ActionListener 17 { 18 19 final int SEATS = 10; // Final integer for the max number of seats 20 final int SmokingEnd = 4; // End of the Smoking Section 21 final int NonSmokingEnd = 9; // End of the Non-Smoking Section 22 23 JLabel preference; // Lists the Section Preferences for the passenger 24 JLabel title; // My PIMP Title 25 JTextField section; // Text Field for the passengers to enter their selection 26 JTextArea output; // Text Area for the passengers to read the instructions/results 27 28 int choice; // User inputed Section choice 29 int smokingCounter = 0; // Counts the number of passengers in the Smoking Section 30 int nonsmokingCounter = 0; // Counts the number of passengers in the Non-Smoking Section 31 32 boolean array[]; //Initializes a global boolean array; 33 34 public void init() 35 { 36 //Creates a new boolean array with max SEATS 37 array = new boolean[ SEATS ]; 38 39 //Creates a 2 JLabels, a JTextField, and a JTextArea 40 title = new JLabel( "Welcome to Chris' Fly'N'Style Airlines" ); 41 preference = new JLabel( "Please type 1 for the Smoking Section and 2 for the Non-Smoking Section"); 42 section = new JTextField( 3 ); 43 output = new JTextArea( 6, 12 ); 44 45 //Add to contentPane 46 Container container = getContentPane(); 47 container.setLayout( new FlowLayout() ); 48 container.add( title ); 49 container.add( preference ); 50 container.add( section ); 51 container.add( output ); 52 53 //Add to ActionListener 54 section.addActionListener( this ); 55 }// ends init() 56 57 public void actionPerformed( ActionEvent actionEvent ) 58 { 59 String input = section.getText(); 60 choice = Integer.parseInt( input );
62 if ( ( array[ NonSmokingEnd ] ) & ( array[ SmokingEnd ] ) ) 63 { 64 output.setText( " \n" ); 65 output.append( " *********************************** \n" ); 66 output.append( " * The plane is completely full. * \n" ); 67 output.append( " * Next flight leaves in 3 hours. * \n" ); 68 output.append( " *********************************** " ); 69 }// ends if 70 71 else if ( choice == 1 ) 72 { 73 if ( ( !array[ smokingCounter ] ) & ( smokingCounter < 5 ) ) 74 { 75 array[ smokingCounter ] = true; 76 output.setText(" ******************************* \n"); 77 output.append( " Chris' Fly'N'Style Airlines \n"); 78 output.append( " ******************************* \n"); 79 output.append( " \n"); 80 output.append( " You have been assigned \n"); 81 output.append( " Seat Number " + ( smokingCounter + 1 )