Docsity

Java Program for Creating a Reservation System for a 10-Seat Airline, Exams of Computer Science

Toggle sidebar
bg1
1/*
2Chris Parks
3CSCI 2350
42/12/05
5Airline.java
6To 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 );
1
pf3

Partial preview of the text

Download Java Program for Creating a Reservation System for a 10-Seat Airline and more Exams Computer Science in PDF only on Docsity!

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 )

  • "\n"); 82 output.append( " in the Smoking Section \n"); 83 84 smokingCounter++; 85 }// ends if 86 87 }// ends else if 88 89 else if (choice==2) 90 { 91 92 if ( ( !array[ array.length - 1 ] ) & ( nonsmokingCounter + 5 <= NonSmokingEnd ) ) 93 { 94 array[ ( nonsmokingCounter + 5 ) ] = true; 95 output.setText(" ******************************* \n"); 96 output.append( " Chris' Fly'N'Style Airlines \n"); 97 output.append( " ******************************* \n"); 98 output.append( " \n"); 99 output.append( " You have been assigned \n"); 100 output.append( " Seat Number " + ( nonsmokingCounter + 6 ) + "\n"); 101 output.append( " in the Non-Smoking Section \n"); 102 103 nonsmokingCounter++; 104 }// ends if 105 106 }// ends else if 107 108 }// ends actionPerformed method 109 110 }// ends class 111 112