The programe will be in Java. The objective of this assignment is to practice ma
ID: 3888228 • Letter: T
Question
The programe will be in Java.
The objective of this assignment is to practice managing a group of objects from creation, update, and search perspectives. In addition, you are to learn how to convert user questions to attributes on the classes, and real answers on the screen. Some of the search functions require that you find multiple instances that satisfy the search criteria. The matched elements must be collected into temporary array lists to display on the screenin a secondary table. Write an application to manage a fleet of airplanes for an airliner. Your application should enable search to answer to the following questions:
1. Find me the first available airplane.
2. How many airplanes are currently available. How many are, otherwise.
3. List all airplanes that are made by Boeing.
4. List all airplanes that were manufactured in a given year, 'x'.
5. Find an available airplane with a minimum of x seats but no more than y seats.
6. Find an airplane with the given serial number. List the attributes of the found airplane.
7. List all airplanes given the model number.
8. List all the airplane manufacturers used by the (this) airliner.
9. When was the last time the fleet catalog was updated.
10. List all airplanes that are available in a given airport
11. L st all airplanes that have expired maintenance certificate.
Your application must enable the creation and update functions for any of the attributes of concern. It will be okay to assume each of these questions are buttons on the left/right side of the screen depending on your design.
Also, through a configuration file enable the creation of multiple instances of airplanes with various characteristics consistent with the requirements above. This will save you from having to retype the same thing multiple times. Make sure to create enough variations to enable a good demo of your solution. Checkboxes should be used to indicate yes or no answers to certain attribut es such as availability, etc. The ability to update some of these attributes is required as well.
Bonus Points: Define secondary filers on the found instances. In this case, you will need a search function on the collected search results.
Explanation / Answer
1) Find first available airplane
class Airline {
/**
* The number of planes on the airport
*/
static final int MAX_PLANES = 10;
public static void main(String[] args) {
boolean done = false; // is the user done with the program?
String[] planes = new String[MAX_PLANES];// the plane list
initializePlanes(planes);
do {
printMainMenu();
int choice = getMainMenuChoice();//choice of the main menu
switch (choice) {
case 1:
findAirplane(planes);
break;
case 2:
done = true;
break;
}
} while (!done);
}
/**
* Print the main menu
*/
static void printMainMenu() {
System.out.println(" Main Menu ");
System.out.println("1. First Available plane");
System.out.println("2. Quit");
System.out.println();
}
/**
* Get the user's choice off the main menu
*/
static int getMainMenuChoice() {
int choice; // choice entered
boolean valid = false; // is choice valid?
do {
System.out.print("===> ");
choice = Console.readInt();
if (1 <= choice && choice <= 2) {
valid = true;
} else {
System.out.println("Invalid choice.");
}
} while (!valid);
return choice;
}
/**
* Initialize each element with null to make every plane available.
*/
static void initializePlanes(String[] planes) {
for (int i = 0; i < planes.length; i++) {
planes[i] = "";
}
}
/**
* Find airplane
*/
static void FindAvailableplane(String[] planes) {
int planeIndex = findAvailablePlanes(planes); // index of first available plane
if (planeIndex == planes.length) {
System.out.println("All airplane are booked. Sorry.");
} else {
String name = getPassengerName(); // passenger's name
planes[planeIndex] = name;
System.out.println(name + " Available airplane is" + (planeIndex+1));
}
}
/* Find the index of the first available plane
*/
static int findAvailablePlane(String[] planes) {
for (int i = 0; i < planes.length; i++) {
if (isEmpty(planes, i)) {
return i;
}
}
}
/**
* Yield whether plane[planeIndex] is an empty seat.
*/
static boolean isEmpty(String[] planes, int planeIndex) {
return planes[planeIndex].equals("");
}
/**
* Input a passenger's name
*/
static String getPassengerName() {
System.out.print("Enter the passenger's name: ");
return Console.readString();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.