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
/* 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started