Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions

Question

1. How do most insects respire ?

Answered: 1 week ago

Question

Who is known as the father of the indian constitution?

Answered: 1 week ago

Question

1.explain evaporation ?

Answered: 1 week ago

Question

Who was the first woman prime minister of india?

Answered: 1 week ago

Question

Explain the concept of going concern value in detail.

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago