SHARE
TWEET

Bomi Experiment 2

a guest Jul 17th, 2019 63 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 java.util.Arrays;
  20.  
  21. public class NewClass {
  22.     // checks customers in and assigns them a boarding pass.
  23.     public static void main(String[] args) {
  24.         System.out.println( "Welcome to Bom Air. Have a safe trip!");
  25.         System.out.println( "Here are the available seats. Please enter 1 to reserve First class seats "
  26.                 + "and 2 to reserve Economy seats. Thanks,");
  27.         Scanner input = new Scanner( System.in );
  28.        
  29.         boolean seats[] = new boolean[20]; // array of seats.
  30.         int FirstClass = 0; // next available first class seat.
  31.         int Economy = 6; // next available economy seat.
  32.        
  33.         //seats = [false,false,false,false,false,false]
  34.         //seats = 0  ,  1  ,  2  ,  3  ,  4  ,  5
  35.        
  36.         int currentIndex = 0;
  37.         int arrayLength = 20;
  38.        
  39.         while( currentIndex < arrayLength ) {
  40.             String seat = "";
  41.            
  42.             if(seats[currentIndex]) {
  43.                 seat = "[X]";
  44.             }else{
  45.                 seat = "[ ]";
  46.             }
  47.             System.out.print(seat);
  48.             ++currentIndex;
  49.         }
  50.        
  51.         while (( FirstClass < 6) ||(Economy < 20))
  52.         {
  53.             int section = input.nextInt();
  54.            
  55.             if (section == 1) //user chose first class.
  56.             {
  57.                 if(FirstClass <6)
  58.                 {
  59.                     //Whenever we update a seat, we need to update our seats array:
  60.                     seats[FirstClass] = true;
  61.                     FirstClass++;
  62.                   System.out.printf("<Boarding pass. "
  63.                           + "Seat type: First class. Seat number: #%d>\n", FirstClass );
  64.                 }//end if.
  65.                 else if (Economy <21)// First Class is full.
  66.                 {
  67.                     System.out.println("First Class is fully booked. "
  68.                             + "Would you like to see Economy class seats?");
  69.                     System.out.println("Please type 1 for Yes and 2 for No.");
  70.                     int Choice = input.nextInt();
  71.                    
  72.                     if ( Choice == 1 )
  73.                     {
  74.                         //Whenever we update a seat, we need to update our seats array:
  75.                         seats[Economy] = true;
  76.                     System.out.printf("<Boarding pass. "
  77.                             + "Seat type: Economy class. Seat number: #%d>\n", Economy );
  78.                     }
  79.                     else
  80.                         System.out.println("Next flight leaves in 3 hours");
  81.                 }// end else if.
  82.             }//end if.
  83.          
  84.             else if ( section == 2 ) //user chose Economy.
  85.                 {
  86.                     if ( Economy < 20)
  87.                     {
  88.                         //Whenever we update a seat, we need to update our seats array:
  89.                         seats[Economy] = true;
  90.                         Economy++;
  91.                     System.out.printf("<Boarding pass. "
  92.                             + "Seat type: Economy class. Seat number: #%d>\n", Economy );
  93.                     }//end if.
  94.                     else if ( FirstClass < 6)// Economy class is full.
  95.                     {
  96.                         System.out.println("Economy class is fully booked. Would you like to see First calss seats? ");
  97.                         System.out.print("Please type 1 for Yes and 2 for No.");
  98.                         int Choice = input.nextInt();
  99.                        
  100.                         if ( Choice == 1 )
  101.                         {
  102.                             //Whenever we update a seat, we need to update our seats array:
  103.                             seats[FirstClass] = true;
  104.                             FirstClass++;
  105.                     System.out.printf("<Boarding pass. "
  106.                           + "Seat type: First class. Seat number: #%d>\n", FirstClass );
  107.                         } //end if.
  108.                         else
  109.                         System.out.println("Next flight leaves in 3 hours.");
  110.                     } // end else if.
  111.                 }//end else if.
  112.         System.out.println();
  113.        
  114.          //seats = [false,false,false,false,false,false]
  115.         //seats = 0  ,  1  ,  2  ,  3  ,  4  ,  5
  116.        
  117.          currentIndex = 6;
  118.          arrayLength = 20;
  119.        
  120.         while( currentIndex < arrayLength ) {
  121.             String seat = "";
  122.            
  123.             if(seats[currentIndex]) {
  124.                 seat = "[X]";
  125.             }else{
  126.                 seat = "[ ]";
  127.             }
  128.             System.out.print(seat);
  129.             ++currentIndex;
  130.         }
  131.        
  132.     }//end while.
  133.     System.out.println("There is no more seat available.");
  134. }//end method checkIn
  135. }//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
 
Top