Advertisement
Guest User

Bomi Experiment 3

a guest
Jul 17th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.52 KB | None | 0 0
  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.        
  37.        
  38.         while (( FirstClass < 6) ||(Economy < 20))
  39.         {
  40.             int currentIndex = 0;
  41.             int arrayLength = 20;
  42.            
  43.             int section = input.nextInt();
  44.            
  45.             if (section == 1) //user chose first class.
  46.             {
  47.                 if(FirstClass <6)
  48.                 {
  49.                     //Whenever we update a seat, we need to update our seats array:
  50.                     seats[FirstClass] = true;
  51.                     FirstClass++;
  52.                   System.out.printf("<Boarding pass. "
  53.                           + "Seat type: First class. Seat number: #%d>\n", FirstClass );
  54.                 }//end if.
  55.                 else if (Economy <21)// First Class is full.
  56.                 {
  57.                     System.out.println("First Class is fully booked. "
  58.                             + "Would you like to see Economy class seats?");
  59.                     System.out.println("Please type 1 for Yes and 2 for No.");
  60.                     int Choice = input.nextInt();
  61.                    
  62.                     if ( Choice == 1 )
  63.                     {
  64.                     System.out.printf("<Boarding pass. "
  65.                             + "Seat type: Economy class. Seat number: #%d>\n", Economy );
  66.                     }
  67.                     else
  68.                         System.out.println("Next flight leaves in 3 hours");
  69.                 }// end else if.
  70.             }//end if.
  71.          
  72.             else if ( section == 2 ) //user chose Economy.
  73.                 {
  74.                     if ( Economy < 20)
  75.                     {
  76.                         //Whenever we update a seat, we need to update our seats array:
  77.                         seats[Economy] = true;
  78.                         Economy++;
  79.                     System.out.printf("<Boarding pass. "
  80.                             + "Seat type: Economy class. Seat number: #%d>\n", Economy );
  81.                     }//end if.
  82.                     else if ( FirstClass < 6)// Economy class is full.
  83.                     {
  84.                         System.out.println("Economy class is fully booked. Would you like to see First calss seats? ");
  85.                         System.out.print("Please type 1 for Yes and 2 for No.");
  86.                         int Choice = input.nextInt();
  87.                        
  88.                         if ( Choice == 1 )
  89.                         {
  90.                             //Whenever we update a seat, we need to update our seats array:
  91.                             seats[FirstClass] = true;
  92.                             FirstClass++;
  93.                     System.out.printf("<Boarding pass. "
  94.                           + "Seat type: First class. Seat number: #%d>\n", FirstClass );
  95.                         } //end if.
  96.                         else
  97.                         System.out.println("Next flight leaves in 3 hours.");
  98.                     } // end else if.
  99.                 }//end else if.
  100.         System.out.println();
  101.        
  102.         while( currentIndex < arrayLength ) {
  103.             String seat = "";
  104.            
  105.             if(seats[currentIndex]) {
  106.                 seat = "[X]";
  107.             }else{
  108.                 seat = "[ ]";
  109.             }
  110.             System.out.print(seat);
  111.             ++currentIndex;
  112.         }
  113.        
  114.     }//end while.
  115.     System.out.println("There is no more seat available.");
  116. }//end method checkIn
  117. }//end class Proj2.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement