USING JAVA OBJECTIVE : The objective of the assignment is to use object-oriented
ID: 3671002 • Letter: U
Question
USING JAVA
OBJECTIVE:
The objective of the assignment is to use object-oriented design techniques to design an application.
DESCRIPTION:
You have been hired to design an airline seating application for the FBN (Fly-By-Night) Airlines. In this portion of the assignment, the task is to do the object oriented design for the application. This system will be used only by the company and its employees. Customers will not interact with the system.
REQUIREMENTS:
Design an application that assigns seats on an airplane. The airplane has 20 seats in first class (five 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 app 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 to 2 in first class, 1 to 3 in economy), and the seating preferences (aisle or window in first class, center or window in economy). Then try to find a match and assign seats. If no match exists, display a message. Your design should include a class named airplane that is not coupled with the scanner or print classes. Follow the design process that is described in the presentation for this topic.
Once you have a conceptual model for your application, you should identify the classes you will need to implement your model. Once the classes have been identified you need to identify their responsibilities and relationships to the other classes
SUBMIT:
1. A UML class diagram showing all your classes and the relationships between them.
2. A sequence diagram of one particular interaction between objects in your application. Label the diagram with the name of the scenario you are modeling.
Explanation / Answer
//program
import java.util.Scanner;
public class Airplane {
public static void main(String[] args) {
/*
The airplane has 20 seats in first class (five rows of 4 seats each,
separated by an aisle)
*/
char firstClassSeats[]=new char[20];
/*
90 seats in economy class (15 rows of 6 seats each,
separated by an aisle).
*/
char economyClassSeats[]=new char[90];
initialize(firstClassSeats,economyClassSeats);
int n1=0;
int n2=0;
while(true)
{
/*
app should take three commands: add passengers,
show seating and quit.
*/
System.out.println("1. Add passengers");
System.out.println("2. Show seating");
System.out.println("3. Quit");
System.out.println("Enter your choice: ");
Scanner scan=new Scanner(System.in);
int choice=scan.nextInt();
switch(choice)
{
case 1: addPassengers(firstClassSeats,economyClassSeats,n1, n2);
break;
case 2: showSeating(firstClassSeats,economyClassSeats);
break;
case 3: System.exit(0);
}
}
}
/*
When passengers are added, ask for the class(first or economy),
the number of passengers traveling together(1 to 2 in first class,1 to 3 in economy),
and the seating preferences(aisle or window in first class,center or window in economy).
*/
/*
Then try to find a match and assign seats.If no match exists, display a message.
*/
private static void addPassengers(char[] firstClassSeats, char[] economyClassSeats, int n1, int n2)
{
System.out.println("Enter the class <first or economy>: ");
Scanner scan=new Scanner(System.in);
String className=scan.nextLine();
int numPassengers=0;
String preference="";
boolean match=false;
scan.nextLine();
if(className.equalsIgnoreCase("first"))
{
System.out.println("Enter the number of passengers traveling together <1 or 2>: ");
numPassengers=scan.nextInt();
System.out.println("Enter the seating preferences <aisle or window>: ");
preference=scan.nextLine();
if((n1+numPassengers)<20)
{
if(numPassengers==1 && preference.equalsIgnoreCase("aisle"))
{
firstClassSeats[n1+numPassengers]='A'; // allocated
match=true;
}
else if(numPassengers==2)
{
firstClassSeats[n1+1]='A'; // allocated
firstClassSeats[n1+2]='A';
match=true;
}
}
}
else if(className.equalsIgnoreCase("economy"))
{
System.out.println("Enter the number of passengers traveling together <1 or 2 or 3>: ");
numPassengers=scan.nextInt();
System.out.println("Enter the seating preferences <center or window>: ");
preference=scan.nextLine();
if((n2+numPassengers)<90)
{
if(numPassengers==1 && (n2+numPassengers)%2!=0 && preference.equalsIgnoreCase("center"))
{
economyClassSeats[n2+1]='A'; // allocated
match=true;
}
else if(numPassengers==2)
{
economyClassSeats[n2+1]='A'; // allocated
economyClassSeats[n2+2]='A';
match=true;
}
else if(numPassengers==3)
{
economyClassSeats[n2+1]='A'; // allocated
economyClassSeats[n2+2]='A';
economyClassSeats[n2+3]='A';
match=true;
}
}
}
if(match==false)
{
System.out.println(" No match exists");
}
}
/*
shows the seating arrangement and allocated seats so far
*/
private static void showSeating(char[] firstClassSeats, char[] economyClassSeats) {
System.out.println("Seating arrangement");
for(int i=0;i<20;i++)
{
System.out.print(firstClassSeats[i]+" ");
if(i%4==0)
System.out.println("");
}
for(int i=0;i<90;i++)
{
System.out.print(economyClassSeats[i]+" ");
if(i%6==0)
System.out.println("");
}
}
private static void initialize(char[] firstClassSeats, char[] economyClassSeats) {
for(int i=0;i<20;i++)
{
firstClassSeats[i]='_';
}
for(int i=0;i<90;i++)
{
economyClassSeats[i]='_';
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.