Question: UML & sequential digrams Design an application that assigns seats on an airplane. The airplane has 20 seats in first class (five rows of 4

UML & sequential digrams

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 (aisleor 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

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

The 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(" ..................."); 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 : "); 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 : "); 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 3>: "); numPassengers=scan.nextInt(); System.out.println("Enter the seating preferences

: "); 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; } }1 } 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]='_'; } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!