Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********************************************************
- *
- * NewClass
- * File : <NewClass.java>
- * Name : <Bomi Kim>
- * Date : <July 17, 2019>
- * Class : <CSIS1400>
- * Version : <3>
- *
- ********************************************************/
- package csis1400;
- /**
- *
- * @author bomi
- */
- //Program to reserve airline seats.
- import java.util.Scanner;
- import javax.swing.*; //add Dialog box.
- public class NewClass {
- // checks customers in and assigns them a boarding pass.
- public static void main(String[] args) {
- JFrame frame = new JFrame("InoutDialong Example #1");
- JOptionPane.showMessageDialog(null,"Welcome to Bom Air. Have a safe trip!");
- JOptionPane.showMessageDialog(null,"Here are the available seats. Please enter 1 to reserve First class seats "
- + "and 2 to reserve Economy seats. Thanks,");
- //Scanner input = new Scanner( System.in );
- boolean seats[] = new boolean[20]; // array of seats.
- int FirstClass = 0; // next available first class seat.
- int Economy = 6; // next available economy seat.
- //seats = [false,false,false,false,false,false]
- //seats = 0 , 1 , 2 , 3 , 4 , 5
- while (( FirstClass < 6) ||(Economy < 20))
- {
- int currentIndex = 0;
- int arrayLength = 20;
- /*
- * So, what if a user enters in something that isn't a number?
- *
- * We can use a try/catch:
- *
- * try{
- */
- //By putting the JOptionPane here we keep relevant code together. Which reduces our cognitive load and makes us more efficient.
- int section = Integer.parseInt(JOptionPane.showInputDialog(frame,"1: First class/ 2: Economy"));
- if (section == 1) //user chose first class.
- {
- if(FirstClass <6)
- {
- seats[FirstClass] = true;
- FirstClass++;
- JOptionPane.showMessageDialog(null, "<Boarding pass. "
- + "Seat type: First class. Seat number: #%d>\n");
- }//end if.
- else if (Economy <21)// First Class is full.
- {
- JOptionPane.showMessageDialog(null, "<Boarding pass. "
- + "First Class is fully booked. "
- + "Would you like to see Economy class seats?");
- //Use showInputPane for this bit
- JOptionPane.showMessageDialog(null, "<Boarding pass. "
- + "Please type 1 for Yes and 2 for No.");
- int Choice = input.nextInt();
- if ( Choice == 1 )
- {
- seats[Economy] = true;
- JOptionPane.showMessageDialog(null,"<Boarding pass. "
- + "Seat type: Economy class. Seat number: #%d>\n");
- }
- else
- JOptionPane.showMessageDialog(null,"Next flight leaves in 3 hours");
- }// end else if.
- }//end if.
- else if ( section == 2 ) //user chose Economy.
- {
- if ( Economy < 20)
- {
- seats[Economy] = true;
- Economy++;
- JOptionPane.showMessageDialog(null,"<Boarding pass. "
- + "Seat type: Economy class. Seat number: #%d>\n");
- }//end if.
- else if ( FirstClass < 6)// Economy class is full.
- {
- JOptionPane.showMessageDialog(null, "Economy class is fully booked. Would you like to see First calss seats? ");
- JOptionPane.showMessageDialog(null,"Please type 1 for Yes and 2 for No.");
- int Choice = input.nextInt();
- if ( Choice == 1 )
- {
- seats[FirstClass] = true;
- FirstClass++;
- JOptionPane.showMessageDialog(null,"<Boarding pass. "
- + "Seat type: First class. Seat number: #%d>\n");
- } //end if.
- else
- JOptionPane.showMessageDialog(null,"Next flight leaves in 3 hours.");
- } // end else if.
- }//end else if.
- System.out.println();
- while( currentIndex < arrayLength ) {
- String seat = "";
- if(seats[currentIndex]) {
- seat = "[X]";
- }else{
- seat = "[ ]";
- }
- System.out.print(seat);
- ++currentIndex;
- }
- /*
- * }
- * catch(Exception e){
- * JOptionPane.showMessageDialog(null,"Input incorrect. Try again.");
- * }
- */
- }//end while.
- JOptionPane.showMessageDialog(null,"");
- JOptionPane.showMessageDialog(null,"There is no more seat available.");
- }//end method checkIn
- }//end class Proj2.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement