SHARE
TWEET

Bomi Experiment 3

a guest Jul 18th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********************************************************
  2.  *
  3.  *  NewClass
  4.  *  File    :  <NewClass.java>
  5.  *  Name    :  <Bomi Kim>
  6.  *  Date    :  <July 17, 2019>
  7.  *  Class   :  <CSIS1400>
  8.  *  Version :  <3>
  9.  *
  10.  ********************************************************/
  11. package csis1400;
  12.  
  13. /**
  14.  *
  15.  * @author bomi
  16.  */
  17. //Program to reserve airline seats.
  18. import java.util.Scanner;
  19. import javax.swing.*; //add Dialog box.
  20.  
  21. public class NewClass {
  22.     // checks customers in and assigns them a boarding pass.
  23.     public static void main(String[] args) {
  24.         JFrame frame = new JFrame("InoutDialong Example #1");
  25.         JOptionPane.showMessageDialog(null,"Welcome to Bom Air. Have a safe trip!");
  26.         JOptionPane.showMessageDialog(null,"Here are the available seats. Please enter 1 to reserve First class seats "
  27.                 + "and 2 to reserve Economy seats. Thanks,");
  28.        
  29.         //Scanner input = new Scanner( System.in );
  30.         boolean seats[] = new boolean[20]; // array of seats.
  31.         int FirstClass = 0; // next available first class seat.
  32.         int Economy = 6; // next available economy seat.
  33.        
  34.         //seats = [false,false,false,false,false,false]
  35.         //seats = 0  ,  1  ,  2  ,  3  ,  4  ,  5
  36.        
  37.         while (( FirstClass < 6) ||(Economy < 20))
  38.         {
  39.             int currentIndex = 0;
  40.             int arrayLength = 20;
  41.            
  42.             /*
  43.              * So, what if a user enters in something that isn't a number?
  44.              *
  45.              * We can use a try/catch:
  46.              *
  47.              * try{
  48.              */
  49.            
  50.             //By putting the JOptionPane here we keep relevant code together. Which reduces our cognitive load and makes us more efficient.
  51.             int section = Integer.parseInt(JOptionPane.showInputDialog(frame,"1: First class/ 2: Economy"));
  52.            
  53.             if (section == 1) //user chose first class.
  54.             {
  55.                 if(FirstClass <6)
  56.                 {
  57.                     seats[FirstClass] = true;
  58.                     FirstClass++;
  59.                   JOptionPane.showMessageDialog(null, "<Boarding pass. "
  60.                           + "Seat type: First class. Seat number: #%d>\n");
  61.                 }//end if.
  62.                 else if (Economy <21)// First Class is full.
  63.                 {
  64.                   JOptionPane.showMessageDialog(null, "<Boarding pass. "
  65.                             + "First Class is fully booked. "
  66.                             + "Would you like to see Economy class seats?");
  67.                  
  68.                   //Use showInputPane for this bit
  69.                   JOptionPane.showMessageDialog(null, "<Boarding pass. "
  70.                             + "Please type 1 for Yes and 2 for No.");
  71.                     int Choice = input.nextInt();
  72.                    
  73.                     if ( Choice == 1 )
  74.                     {
  75.                     seats[Economy] = true;
  76.                    
  77.                     JOptionPane.showMessageDialog(null,"<Boarding pass. "
  78.                             + "Seat type: Economy class. Seat number: #%d>\n");
  79.                     }
  80.                     else
  81.                     JOptionPane.showMessageDialog(null,"Next flight leaves in 3 hours");
  82.                 }// end else if.
  83.             }//end if.
  84.          
  85.             else if ( section == 2 ) //user chose Economy.
  86.                 {
  87.                     if ( Economy < 20)
  88.                     {
  89.                         seats[Economy] = true;
  90.                         Economy++;
  91.                     JOptionPane.showMessageDialog(null,"<Boarding pass. "
  92.                             + "Seat type: Economy class. Seat number: #%d>\n");
  93.                     }//end if.
  94.                     else if ( FirstClass < 6)// Economy class is full.
  95.                     {
  96.                         JOptionPane.showMessageDialog(null, "Economy class is fully booked. Would you like to see First calss seats? ");
  97.                         JOptionPane.showMessageDialog(null,"Please type 1 for Yes and 2 for No.");
  98.                         int Choice = input.nextInt();
  99.                        
  100.                         if ( Choice == 1 )
  101.                         {
  102.                             seats[FirstClass] = true;
  103.                             FirstClass++;
  104.                             JOptionPane.showMessageDialog(null,"<Boarding pass. "
  105.                           + "Seat type: First class. Seat number: #%d>\n");
  106.                         } //end if.
  107.                         else
  108.                             JOptionPane.showMessageDialog(null,"Next flight leaves in 3 hours.");
  109.                     } // end else if.
  110.                 }//end else if.
  111.         System.out.println();
  112.        
  113.         while( currentIndex < arrayLength ) {
  114.             String seat = "";
  115.            
  116.             if(seats[currentIndex]) {
  117.                 seat = "[X]";
  118.             }else{
  119.                 seat = "[ ]";
  120.             }
  121.             System.out.print(seat);
  122.             ++currentIndex;
  123.         }
  124.        
  125.         /*
  126.          * }
  127.          * catch(Exception e){
  128.          * JOptionPane.showMessageDialog(null,"Input incorrect. Try again.");
  129.          * }
  130.          */
  131.        
  132.     }//end while.
  133.     JOptionPane.showMessageDialog(null,"");
  134.     JOptionPane.showMessageDialog(null,"There is no more seat available.");
  135. }//end method checkIn
  136. }//end class Proj2.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top