Write a program that assigns seats on an airplane. Assume the airplane has 20 se
ID: 3667053 • Letter: W
Question
Write a program that assigns seats on an airplane. Assume the airplane has 20 seats in the first class (5 rows of 4 seats
each, separated by an aisle) and 90 seats in economy class (15 rows of 6 seats each, separated by an aisle). Your
program should take three commands: add passengers, show seating, and quit. When passengers are added, ask for the
class (first or economy), the number of passengers traveling together (1 or 2 in the first class; 1 to 3 in economy), and
the seating preference (aisle or window in the first class; aisle, center, or window in economy). Then try to find a match
and assign the seats. If no match exists, print a message stating as such. Your solution should include a class
Airplane that is not coupled with the Scanner or Printstream classes. Be sure to include any other classes that
you need to complete this program using the design process described in Chapter 12.
Explanation / Answer
package com.dq.thematrix.main.java.test;
//cc RowFilterExample Example using a filter to select specific rows
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HConnection;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.log4j.Logger;
import com.dq.thematrix.main.java.hbase.ConnectionFactory;
public class Hbasetask1 {
public static void main(String args[])
{
String classType=null,noOfPassengers=null,seatPreference=null;
;
Aeroplane aer=new Aeroplane();
while(true)
{
System.out.println("1. Add ");
System.out.println("2. Show ");
System.out.println("3. quit ");
Scanner a = new Scanner(System.in);
String ch=a.nextLine();
if(ch.equals("1")){
System.out.println("choose Class");
System.out.println("1. First Class");
System.out.println("2. Economy Class");
classType=a.nextLine();
if(classType.equals("1"))
classType="First";
else if(classType.equals("2"))
classType="Economy";
System.out.println("Enter no of passengers");
noOfPassengers=a.nextLine();
System.out.println("Choose seat preference");
System.out.println("1. Window");
System.out.println("2. Aisle");
seatPreference=a.nextLine();
Boolean check=aer.checkStatus(classType,noOfPassengers,seatPreference);
if(!check)
System.out.println("No such seats available");
else System.out.println("Booked Perfectly!");
}
else if(ch.equals("2"))
{
}
else if(ch.equals("3"))
break;
}
}
}
class Aeroplane
{
int classDetaisl[][]=new int[20][90]; //For Economy and First class
boolean checkStatus(String classType, String noOfPassengers, String seatPreference)
{
boolean flag=false;
// HEre check for differenr combinations
return flag;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.