Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a graphical Java program that assigns seats to clients. Use buttons (JButt

ID: 3621740 • Letter: W

Question

Write a graphical Java program that assigns seats to clients. Use buttons (JButton objects) to represent the seats. Display the seats as a grid with five rows and 3 columns. Initially all seats are available and are marked with the values 1 through 15.
When the program is started a dialog box providing instructions to the user must be displayed. This dialog box should have an OK button only. Your graphical interface should also contain a Quit button.
When a user clicks the button for an unassigned seat, a confirmation dialog box must be displayed asking the user if they really want to book the seat. This dialog box must have yes, no, and cancel buttons. If the user clicks the yes button, then the seat button label should change to the word "Occupied" to indicate that the seat is booked. If the no or cancel button is clicked the dialog box closes and no additional action is taken.
If a user clicks on an assigned seat, then a dialog box must be displayed indicating that the seat is already taken. This dialog box should have an OK button only.
When the last seat has been assigned, a dialog box informing the user that no empty seats remain must be displayed. This dialog box should have an OK button only.
The Quit button terminates the program. When this button is clicked, a dialog box must be displayed to confirm that the user really wants to quit the program. The confirmation dialog box must have yes, no, and cancel buttons. If the user clicks the yes button then the GUI closes and the program ends.
Create separate panels for the seat buttons and the exit button. Use layout managers to arrange the panels and the seat buttons.
The frame title bar must display a heading that represents the name of your application (for example, Acme Airline Reservation System).
Your program must write the button labels to an ArrayList, then print its contents to the NetBeans output window when the user clicks either the Quit or Exit button.

Explanation / Answer

this is definitely not the prettiest GUI in the world as i havent written GUI's for Java in a long time, but it gets the job done. import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; import java.util.ArrayList; public class SeatSelector extends JPanel implements ActionListener { static JFrame frame; JButton seat1 = new JButton("1"); JButton seat2 = new JButton("2"); JButton seat3 = new JButton("3"); JButton seat4 = new JButton("4"); JButton seat5 = new JButton("5"); JButton seat6 = new JButton("6"); JButton seat7 = new JButton("7"); JButton seat8 = new JButton("8"); JButton seat9 = new JButton("9"); JButton seat10 = new JButton("10"); JButton seat11 = new JButton("11"); JButton seat12 = new JButton("12"); JButton seat13 = new JButton("13"); JButton seat14 = new JButton("14"); JButton seat15 = new JButton("15"); JButton quitButton = new JButton("Quit"); int choice = 0, counter = 0; public static void main(String[] args) { frame = new JFrame("Seat Selector"); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(1, 0)); contentPane.add(new SeatSelector()); frame.pack(); frame.setVisible(true); } public SeatSelector() { jbInit(); } private void jbInit() { this.setLayout(new BorderLayout()); JPanel seatPanel = new JPanel(); seatPanel.setPreferredSize(new Dimension(300,150)); seatPanel.setLayout(new GridLayout(5,3)); seatPanel.add(seat1); seatPanel.add(seat2); seatPanel.add(seat3); seatPanel.add(seat4); seatPanel.add(seat5); seatPanel.add(seat6); seatPanel.add(seat7); seatPanel.add(seat8); seatPanel.add(seat9); seatPanel.add(seat10); seatPanel.add(seat11); seatPanel.add(seat12); seatPanel.add(seat13); seatPanel.add(seat14); seatPanel.add(seat15); seat1.addActionListener(this); seat2.addActionListener(this); seat3.addActionListener(this); seat4.addActionListener(this); seat5.addActionListener(this); seat6.addActionListener(this); seat7.addActionListener(this); seat8.addActionListener(this); seat9.addActionListener(this); seat10.addActionListener(this); seat11.addActionListener(this); seat12.addActionListener(this); seat13.addActionListener(this); seat14.addActionListener(this); seat15.addActionListener(this); quitButton.addActionListener(this); this.add(seatPanel, BorderLayout.WEST); this.add(quitButton,BorderLayout.SOUTH); JOptionPane.showMessageDialog(null, "Choose any seat you wish to book, press Quit to exit"); } public void actionPerformed(ActionEvent e) { if(e.getSource() != quitButton) { if(((JButton)e.getSource()).getText() != "Occupied") choice = JOptionPane.showConfirmDialog(null, "Do you want to book this seat?"); else JOptionPane.showMessageDialog(null, "This seat is already taken"); if(choice == JOptionPane.YES_OPTION) { ((JButton)e.getSource()).setText("Occupied"); counter++; if(counter == 15) JOptionPane.showMessageDialog(null, "All seats have been booked"); } } else { choice = JOptionPane.showConfirmDialog(null, "Do you really want to exit?"); if(choice == JOptionPane.YES_OPTION) { ArrayList list = new ArrayList(); list.add(seat1.getText()); list.add(seat2.getText()); list.add(seat3.getText()); list.add(seat4.getText()); list.add(seat5.getText()); list.add(seat6.getText()); list.add(seat7.getText()); list.add(seat8.getText()); list.add(seat9.getText()); list.add(seat10.getText()); list.add(seat11.getText()); list.add(seat12.getText()); list.add(seat13.getText()); list.add(seat14.getText()); list.add(seat15.getText()); for(int i = 0; i < 15; i++) System.out.println(list.get(i)); System.exit(1); } } } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote