need to Write a Java Applet as a small airline reservation system. The system has only one airplane with 10 seats: 1 to 5 for first class and 6 to 10 for economy. The applet has two buttons and a text field for boarding pass. If the user clicked the First Class button, a currently available first class seat is printed in the boarding pass. If the user clicked the Economy button, a currently available economy seat is printed in the boarding pass. If the user selected section has no available seat, your program should ask if the user is OK with the other section seats. If the user clicked OK, you print the boarding pass of the assigned seat. If the user clicked Cancel, print "Next flight leaves in 3 hours"
when i run my applet and click firstclass or economy all i get in the outputField is "Next flight leaves in 3 hours." it doesn't go to seats 1 through 5 for firstclass or 6 through 10 for economy.
also as for the my program should ask if the user is OK with the other section seats. If the user clicked OK, you print the boarding pass of the assigned seat. If the user clicked Cancel, print "Next flight leaves in 3 hours"
i know its
choice = Integer.parseInt(JOptionPane.showInputDialog("Are you OK with First Class. (click OK or Cancel")); if (choice == (not sure what i put here??) else JOptionPane.showMessageDialog("Next flight leaves in 3 hours."); { }
here is my code
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Assign7 extends JApplet implements ActionListener { JTextField outputField; JButton firstClassButton, economyButton; int section, seats[], firstclass; int economy, people, choice; public void init() { Container container = getContentPane(); container.setLayout(new FlowLayout()); firstClassButton = new JButton( "First Class" ); firstClassButton.addActionListener( this ); container.add(firstClassButton); economyButton = new JButton( "Economy" ); economyButton.addActionListener( this ); container.add(economyButton); outputField = new JTextField ( 17 ); outputField.setEditable(false); container.add(outputField); seats = new int[ 11 ]; firstclass = 1; economy = 6; } public void actionPerformed( ActionEvent actionEvent ) { if ( actionEvent.getSource() == firstClassButton && people <=10) { if ( firstclass <= 5 && seats[ firstclass ] == 0 ) { outputField.setText ("Boarding Pass: Seat " + firstclass+ " FirstClass"); seats[ firstclass++ ] = 1; people++; } else if ( firstclass > 0 && economy <= 6) { outputField.setText ("FirstClass is full. Economy?"); } else outputField.setText("Next flight leaves in 3 hours."); } else if (actionEvent.getSource() == economyButton && people <=10) { if ( economy >= 5 && seats[ economy ] == 0) { outputField.setText ("Boarding Pass: Seat " +economy+ " Economy"); seats[ economy++ ] = 1; people++; } else if ( economy > 0 && firstclass <= 6 ) { outputField.setText("Economy is full. FirstClass?"); } else outputField.setText ("Next flight leaves in 3 hours."); } } } { }