Question

In: Computer Science

20 people line up to board an airplane. Each has a boarding pass with assigned seat....

20 people line up to board an airplane. Each has a boarding pass with assigned seat. However, the first person to board has lost his boarding pass and takes a random seat. After that, each person takes the assigned seat if it is unoccupied, and one of unoccupied seats at random otherwise. Write an efficient MPI program with 2 distributed nodes to calculate the percentage of people who occupied their assigned seats and percentage of people who occupied seats randomly.( Pease type the code and send me) it's from parallel distributing computing subject(MPI program)

Solutions

Expert Solution

import java.util.Scanner;

public class AirplaneSeating {

static int filled = 0;

public static void main(String[] args) {
// two- dimensional array with 7 rows and 4 columns
char[][] seats = new char[7][4];
for (int i = 0; i < 7; i++) {
seats[i][0] = 'A';
seats[i][1] = 'B';
seats[i][2] = 'C';
seats[i][3] = 'D';
}

String seatNumber = " ";
String q = " ";
System.out.println("Welcome to the Airplane Seating Reservation System.");
System.out.println("Please enter the seat (e.g.- 1A) you wish to reserve.");
System.out.println("Enter q to exit.");
Scanner keyboard = new Scanner(System.in);
seatNumber = keyboard.nextLine();
if (seatNumber.equals("q")) {
System.out.println("Program ended.");
System.exit(0);
}
// print seating pattern and put an X in the seatNumber location
while (filled < 28 && seatNumber.length() > 0) {
int row = seatNumber.charAt(0) - '1';
int col = seatNumber.charAt(1) - 'A';
if (row < 0 || row > 7 || col < 0 || col > 4) {
System.out.println("Input error. Enter seat to assign (e.g., '1A')," + "or q to quit.");
seatNumber = keyboard.nextLine();
if (seatNumber.equals("q")) {
System.out.println("Program ended.");
System.exit(0);
}
} else {
if (seats[row][col] != 'X') {
seats[row][col] = 'X';
filled++;
System.out.println(" ");
printSeats(seats);
}
if (filled < 28) {
System.out.println("Enter seat to assign (e.g., '1A')," + "or q to quit.");
seatNumber = keyboard.nextLine();
if (seatNumber.equals("q")) {
System.out.println("Program ended.");
System.exit(0);
}
}
}
}
}

private static void printSeats(char[][] seats) {
System.out.println("Row");
for (int i = 0; i < seats.length; i++) {
System.out
.println((i + 1) + " " + seats[i][0] + " " + seats[i][1] + " " + seats[i][2] + " " + seats[i][3]);

}
int numberOfSeatsAvailable = (28 - filled);
System.out.println("There are " + numberOfSeatsAvailable + " seats available.");
} // end main
} // end class


Related Solutions

1) In the airport there are 10 airplanes waiting to board. If each airplane has the...
1) In the airport there are 10 airplanes waiting to board. If each airplane has the same seat distribution, 20 first class, 40 business class and 140 economy class and they are boarding randomly: what is the probability that the first passenger boarding in 4 of the 10 airplanes is from the economy class. What is the mean of this distribution? 2) Using the following data determine the median, mode and 47% percentile. 6, 22, 14, 12, 13, 14, 16,...
1. A company has two open seats, Seat A and Seat B, on its board of...
1. A company has two open seats, Seat A and Seat B, on its board of directors. There are six candidates vying for these 2 positions. There will be a single election to determine the winner of both open seats. As the owner of 10,000 shares of stock, you will receive one vote per share for each open seat. You decide to cast all 20,000 of your votes for a single candidate. (i) What is this type of voting called?...
You want a seat on the board of directors of Four Keys, Inc. The company has...
You want a seat on the board of directors of Four Keys, Inc. The company has 215,000 shares of stock outstanding and the stock sells for $72 per share. There are currently 4 seats up for election. If the company uses cumulative voting, how many shares do you need to guarantee that you will be elected to the board?
The following table belongs to a pet boarding company. Each pet that is kept has a...
The following table belongs to a pet boarding company. Each pet that is kept has a type (species) and weight, an owner and the information where it is kept (which pen). The fee depends on the pen. It also depends on the owner because owners can have special rates.    Pet_id Type Weight Pen Fee Owner_id O_name 2800 Cat 9.2 P02 20 11 Susan 1739 Cat 7.5 P01 25 28 Brett 9981 Dog 3.3 P02 30 29 Jason Identify the...
An airplane is approaching point A along a straight line and at a constant altitude h. At 10:00 am, the angle of elevation of the airplane is 20° and at 10:01 it is 60°
An airplane is approaching point A along a straight line and at a constant altitude h. At 10:00 am, the angle of elevation of the airplane is 20° and at 10:01 it is 60°. What is the altitude h of the airplane if the speed of the airplane is constant and equal to 600 miles/hour? (round answer to 2 decimal places).
10 couples go to a party (So 20 people in total). Each of the 20 people...
10 couples go to a party (So 20 people in total). Each of the 20 people are randomly seated at a large round table with 20 chairs. Let Xi = 1, for i = 1, 2, . . . , 20, if the i th person is sitting next to the other person in their couple, and 0 otherwise. Let Y be the total number of people who are seated next to their partner. (Note that the Xi ’s all...
The Board of Directors of ABC Co Ltd has assigned you the task of analysing the...
The Board of Directors of ABC Co Ltd has assigned you the task of analysing the Discounted Cash Flow (DCF) technique for appraising large investment decisions. Write a report to them giving your observations.
We are testing people to see if the rate of use of seat belts has changed...
We are testing people to see if the rate of use of seat belts has changed from a previous value of 82%. Suppose that in our random sample of 75 people, we see that 66 have the seat belt fastened. The researcher is interested in α = 0.1 level test. Step 1 State the null and alternative hypotheses. Step 2 Write down the appropriate test statistic and the rejection region of your test (report z critical(s)) Step 3 Compute the...
A) At the local pizza parlor people line up outside in their masks and proceed 1...
A) At the local pizza parlor people line up outside in their masks and proceed 1 at a time into the store to pay for and pick up the pizza. The manager who receives the orders for the pizzas wants to minimize peoples wait time. So she keeps track of the wait times for 25 people in mimutes: 40, 32, 5, 14, 7, 9, 13, 8, 9, 15, 11, 9, 15, 13, 14, 14, 7, 10, 13, 15, 18, 8,...
you have been assigned to a short term team, made up of people you have never...
you have been assigned to a short term team, made up of people you have never met. What can you do to make your first meeting with your new team productive?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT