JAVA PROGRAM:
package test.airline;
import java.util.Scanner;
public class AirlineDriver {
private static final int ROW_COUNT = 5;
private static final int SEAT_COUNT_PER_ROW = 4;
private String[][] passengerSeats = null;
//INITILIZES THE COBSTRUCTOR WITH ARRAY
public AirlineDriver(){
passengerSeats = new
String[ROW_COUNT][SEAT_COUNT_PER_ROW];
for(int i = 0; i< ROW_COUNT;
i++){
passengerSeats[i] = new String[]{"A","B","C","D"};
}
}
public static void main(String[] args){
AirlineDriver ad = new
AirlineDriver();
String seat = null;
String row = null;
Scanner scan = new
Scanner(System.in);
boolean isContinue = true;
while(isContinue){ //CONTINUE
LOOPING
System.out.println("Enter row and seat"); // ENTER ROW AND SEAT
NUMBER FROM USER
row =
scan.next();
seat =
scan.next();
int r =
Integer.parseInt(row) -1; // User will enter between 1 to 5
//however to
make it proper array index I have subtracted 1 from it to make it
zero based
String c =
null;
if(!seat.equals("-1")){//if user enters -1 for the seat the while
lop will terminate
if(seat.length()==1 &&
Character.isLowerCase(seat.charAt(0))){
c = seat.toUpperCase();
}
boolean isAvailable = false;
for(int i = 0 ; i < SEAT_COUNT_PER_ROW;
i++){
if(!ad.passengerSeats[r][i].equals("X") &&
c.equals(ad.passengerSeats[r][i])){ //the seat is available and
matches with user requested seat
ad.passengerSeats[r][i] = "X";//mark the seat as occupied with
X
isAvailable = true;
break;//break out of the loop
}
}
if(!isAvailable){ //if not available show
message
System.out.println("The seat
is not available right now.");
}
ad.display(ad.passengerSeats);// display
passenger seat situation
}else{
isContinue = false;
}
}
}
private void display(String[][] passengersSeat){
StringBuilder str = new
StringBuilder();
for(int i = 0; i<
passengersSeat.length;i++){
str.append(i+1).append(String.join("",passengersSeat[i]));
str.append("
");
}
System.out.println(str.toString());
}
}
OUTPUT
Enter row and seat
1 a
1XBCD 2ABCD 3ABCD 4ABCD 5ABCD
Enter row and seat
2 b
1XBCD 2AXCD 3ABCD 4ABCD 5ABCD
Enter row and seat
3 c
1XBCD 2AXCD 3ABXD 4ABCD 5ABCD
Enter row and seat
4 d
1XBCD 2AXCD 3ABXD 4ABCX 5ABCD
Enter row and seat
2 b
The seat is not available right now.
1XBCD 2AXCD 3ABXD 4ABCX 5ABCD
Enter row and seat
3 -1
EXPLANATION:
COMMENTS GIVEN within the code.
Labs CSIT 210 Introduction to Programming LAB 9B Arrays Change the program AirlineDriver.java to assign passenger seats in an airplane. Chesapeake Airlines is a small commuter airline with seats for...
I have to write a C program to assign seats on each flight of the airline’s only plane (capacity: 40 seats, in 10 rows). For the sake of simplicity, assume that each row has 4 seats labeled A, B, C, D. Your program should display the following menu of alternatives: Please type 1 for "first class" Please type 2 for "business class" Please type 3 for “economy class”. If the person types 1, then your program should assign a seat...
6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you will practice working with arrays. Your program will read lines of text from the keyboard and use an array to track the number of times each letter occurs in the input text. You will use the contents of this array to generate a histogram (bar graph) indicating the relative frequencies of each letter entered. Test cases are available in this document. Remember, in addition...