not sure where i input the... 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"
i know its but cant get the input to work..
choice = Integer.parseInt(JOptionPane.showInputDialog("Are you OK with First Class. (click OK or Cancel")); hours."); { }
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."); } } } { }