Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please give the exact code to match the exact outputs in java thanks and provide

ID: 3812140 • Letter: P

Question

Please give the exact code to match the exact outputs in java thanks and provide all the neccessary java files Provide all the java files with complete code thanks

Flight.java(given by the instructor, it needs to be modified for this assignment)
Schedule.java(given by the instructor, it needs to be modified for this assignment)
FlightNumberComparator.java
DepartureComparator.java
Sorts.java
FlightManagement.java

These are the neccessary files needed to get the correct output which is given in the end down below, please update and answer with correct java code in all files thank you..

Assignment8 file -

You are required, but not limited, to turn in the following source files:

Assignment8.java(More code need to be added)
Flight.java(given by the instructor, it needs to be modified for this assignment)
Schedule.java(given by the instructor, it needs to be modified for this assignment)
FlightNumberComparator.java
DepartureComparator.java
Sorts.java
FlightManagement.java

Requirements to get full credits in Documentation

The assignment number, your name, StudentID, Lecture number/time, and a class description need to be included at the top of each file/class.

A description of each method is also needed.

Some additional comments inside of methods(especially for the "main" method) to explain code that are hard to follow should be written.

You can look at the Java programs in the text book to see how comments are added to programs.

Skills to be Applied

In addition to what has been covered in previous assignments, the use of the following items, discussed in class, will probably be needed:

Sorting
Searching
Aggregate Objects
Interfaces
Serialization
File read/write

Program Description

Class Diagram:

Schedule

The Schedule class implements the "Serializable" interface so that its object can be stored. (The Serializable interface is defined in the "java.io" package.) It needs to define the following method:

public void copy(Schedule other)

It needs to copy every member variable value from "other" parameter to their corresponding variable of the object itself using "this" reference. For instance, if we have two objects of Schedule, schedule1 and schedule2, then, executing the following statement:

schedule1.copy(schedule2)

should resulting to have the object schedule1 to have the same city, year, month, date, and time value as the ones for schedule2, but schedule1 and schedule2 should not become aliases.

Flight

The Flight class implements the "Serializable" interface so that its object can be stored. (The Serializable interface is defined in the "java.io" package.) It needs to define the following method:

public void copy(Flight other)

It needs to copy every member variable value from "other" parameter to their corresponding variable of the object itself using "this" reference.

FlightNumberComparator

The FlightNumberComparator class implements the "Comparator" interface (The Comparator interface is in "java.util" package.). It needs to define the following method that was an inherited abstract method from Comparator interface:

public int compare(Object first, Object second)

(Note that you can also define:
public int compare(Flight first, Flight second)
instead by making the class implements Comparator.

If the first argument object has a name of its airlines lexicographically less than that of the second argument, an int less than zero is returned. If the first argument object has a name of its airlines lexicographically larger than that of the second argument, an int greater than zero is returned. If their airlines names are same, then their flight numbers should be compared. If they have same airlines and flight numbers, then 0 should be returned.

DepartureComparator

The DepartureComparator class implements the "Comparator" interface (The Comparator interface is in "java.util" package.). It needs to define the following method that was an inherited abstract method from Comparator interface:

public int compare(Object first, Object second)

(Note that you can also define:
public int compare(Flight first, Flight second)
instead by making the class implements Comparator.

If the first argument object has a city lexicographically less than that of the second argument, an int less than zero is returned. If the first argument object has a city lexicographically larger than that of the second argument, an int greater than zero is returned. If their cities are same, then their departure years should be compared. (if the first argument object has a smaller year, then it should return a negative integer. If the first argument object has a larger year, then it should return a positive integer.) If their cities and departure years are same, then their departure months should be compared. If their cities, departure years, and departure months are same, then their departure date should be compared. If their cities, departure years, departure months, and departure dates are same, then their departure time should be compared. If their cities, departure years, departure months, departure dates, and departure time are same, then 0 should be returned.

Sorts

The Sorts class is a utility class that will be used to sort a list of Flight objects. Sorting algorithms are described in the algorithm note posted under Notes section of the course web site. These algorithms sort numbers stored in an array. It is your job to modify it to sort an array of objects.
The Sorts class object will never be instantiated. It must have the following methods:

public static void sort(Flight[] flightList, int size, Comparator)

Your sort method utilizes the compare method of the parameter Comparator object to sort. You can use one of Selection sort or Insertion Sort. The parameter size specifies how many first elements should be sorted. Note that not all elements in the array should be sorted, since some of them will be null pointers.

FlightManagement

The FlightManagement class has a list of Flight objects that can be organized at the flight management system. The flight management system will be a fully encapsulated object. The FlightManagement class implements the Serializable interface.
It has the following attributes:

The following public methods should be provided to interact with the flight management system:

No input/output should occur in the flight management system. User interaction should be handled only by the driver class.

You may add other methods to the class in order to make your life easier.

Assignment8

All input and output should be handled in Assignment8 class. The main method should start by displaying this updated menu in this exact format:

Choice Action
------ ------
A Add Flight
C Create FlightManagement
D Search by Flight Number
E Search by Departure
L List Flights
O Sort by Flight Number
P Sort by Departure
Q Quit
R Remove by Flight Number
T Close FlightManagement
U Write Text to File
V Read Text from File
W Serialize FlightManagement to File
X Deserialize FlightManagement from File
? Display Help

Next, the following prompt should be displayed:

What action would you like to perform?

Read in the user input and execute the appropriate command. After the execution of each command, redisplay the prompt. Commands should be accepted in both lowercase and uppercase. The following commands are modified or new.

Add Flight

This part is already implemented in Assignment8.java file.
Please see the case A in the main of Assignment8.java.

Create FlightManagement

This part is already implemented in Assignment8.java file.
Please see the case C in the main of Assignment8.java.

Search by Flight Number

This part is already implemented in Assignment8.java file.
Please see the case D in the main of Assignment8.java.

Search by Departure

This part is already implemented in Assignment8.java file.
Please see the case E in the main of Assignment8.java.

Sort by Flight Number

This part is already implemented in Assignment8.java file.
Please see the case O in the main of Assignment8.java.

Remove by Flight Number

This part is already implemented in Assignment8.java file.
Please see the case R in the main of Assignment8.java.

List Flights

Each Flight object information in the flight list should be displayed using the toString method provided in the Flight class. (and use listFlights( ) method in the FlightManagement class.)
This part is already implemented in Assignment8.java file.
Please see the case L in the main of Assignment8.java.

Close FlightManagement

Delete all Flight objects. Then, display the following:

flight management system closed
This part is already implemented in Assignment8.java file.
Please see the case R in the main of Assignment8.javaT

Write Text to File

Your program should display the following prompt:

Please enter a file name to write:

Read in the filename and create an appropriate object to get ready to read from the file. Then it should display the following prompts:

Please enter a string to write in the file:

Read in the string that a user types, say "input", then attach " " at the end of the string, and write it to the file. (i.e. input+" " string will be written in the file.)

If the operation is successful, display the following:

FILENAME was written

Replace FILENAME with the actual name of the file.

Use try and catch statements to catch IOException. The file should be closed in a finally statement.

Read Text from File

Your program should display the following prompt:

Please enter a file name to read:

Read in the file name create appropriate objects to get ready to read from the file. If the operation is successful, display the following (replace FILENAME with the actual name of the file):

FILENAME was read

Then read only the first line in the file, and display:

The first line of the file is:

CONTENT

where CONTENT should be replaced by the actual first line in the file.

Your program should catch the exceptions if there are. (Use try and catch statement to catch, FileNotFoundException, and the rest of IOException.)

If the file name cannot be found, display

FILENAME was not found

where FILENAME is replaced by the actual file name.

Serialize FlightManagement to File

Your program should display the following prompt:

Please enter a file name to write:

Read in the filename and write the serialized FlightManagement object out to it. Note that any objects to be stored must implement Serializable interface. The Serializable interface is defined in java.io.* package. If the operation is successful, display the following:

FILENAME was written

Replace FILENAME with the actual name of the file.

Use try and catch statements to catch NotSerializableExeption and IOException.

Deserialize FlightManagement from File

Your program should display the following prompt:

Please enter a file name to read:

Read in the file name and attempt to load the FlightManagement object from that file. Note that there is only one FlightManagement object in the Assignment8 class, and the first object read from the file should be assigned to the FlightManagement object. If the operation is successful, display the following (replace FILENAME with the actual name of the file):

FILENAME was read

Your program should catch the exceptions if there are.

(Use try and catch statement to catch ClassNotFoundException, FileNotFoundException, and the rest of IOException.)

See the output files for exception handling.

Attribute name Attribute type Description flightList an array of Flight objects A list of Flight objects in the flight management system currentFlightsCount int the number of Flight objects created and stored in the flightList maxSize int the maximum number of Flight objects that can be stored in the flightList array. It is also the size of the flightList array. Schedule FlightNumberComparator Flight +compare(Object,Object) int Flight Management -flightList: Flight0 -currentFlightsCount:int maxSize nt +FlightManagement(int) +flightNumberExists (String,int):int +departureExists (String, int, nt, int, String) int taddFlight String. nt, String, String, int, String):boolean int tremove FlightNumber(String,int):boolean ttsortByFlightNumber(): void tsortByDeparture(): void +list Flights0: String +close FlightManagement():void Assignments CSE205 Arizona State University-Spring 2017 Departure Comparator +compare(Object,Object):int Assignment8 +main(Stringll): void +print Menu (0:void Sorts sort (Flight0, int, Comparator Flight :void

Explanation / Answer

Copy method for Schedule class

    public void copy(Schedule other) {
       this.setCity(other.getCity());
       this.setTime(other.getTime());
       this.setDate(other.getDate());
       this.setMonth(other.getMonth());
       this.setYear(other.getYear());
   }

Copy method for Flight class

      public void copy(Flight other) {

       this.setAirlines(other.getAirlines());
       this.setFlightNum(other.getFlightNum());
       this.getDeparture().copy(other.getDeparture());
       this.getArrival().copy(other.getArrival());
   }

import java.util.Comparator;

public class FlightNumberComparator implements Comparator<Flight> {

   /**
   * Compares two flights
   */
   @Override
   public int compare(Flight f1, Flight f2) {
       int compareValue = f1.getAirlines().compareToIgnoreCase(f2.getAirlines());
      
       if (compareValue == 0) {   // If airline names are same
           compareValue = f1.getFlightNum() - f2.getFlightNum();   // compare flight num
       }
      
       return compareValue;
   }
}

import java.util.Comparator;

public class DepartureComparator implements Comparator<Flight> {

   /**
   * Compares departure of two flights
   */
   @Override
   public int compare(Flight f1, Flight f2) {
       int compareValue = f1.getDeparture().getCity().compareToIgnoreCase(f2.getDeparture().getCity());

       if (compareValue == 0) { // If dep city are same
           // compare dep year
           compareValue = f1.getDeparture().getYear() - f2.getDeparture().getYear();
          
           if (compareValue == 0) { // If dep year are same
               // compare dep month
               compareValue = f1.getDeparture().getMonth() - f2.getDeparture().getMonth();
          
               if (compareValue == 0) { // If dep month are same
                   // compare dep date
                   compareValue = f1.getDeparture().getDate() - f2.getDeparture().getDate();
                  
                   if (compareValue == 0) { // If dep date are same
                       // compare dep time
                       compareValue = f1.getDeparture().getTime().compareToIgnoreCase(f2.getDeparture().getTime());
                   }
               }
           }
       }

       return compareValue;
   }
}

import java.util.Comparator;

public class Sorts {

   public static void sort(Flight[] flightList, int size, Comparator<Flight> comparator) {
      
       // For each flight
       for (int i = 0; i < size - 1; i++) {
           int min = i;
          
           // Search for flight flightList[j] which is comparatively smaller than flightList[i]
           for (int j = i + 1; j < size; j++) {
              
               if (comparator.compare(flightList[j], flightList[i]) < 0) {
                   // Set min as j
                   min = j;
               }
           }
          
           // Swap if flightList[i], flightList[j] if a new min is found
           if (min != i) {
               Flight temp = new Flight();
               // Copy flightList[i] to temp
               temp.copy(flightList[i]);
              
               // Copy flightList[min] to flightList[i]
               flightList[i].copy(flightList[min]);
              
               // Copy temp to flightList[min]
               flightList[min] = temp;
           }
       }
   }
}

import java.util.Comparator;

public class Sorts {

   public static void sort(Flight[] flightList, int size, Comparator<Flight> comparator) {
      
       // For each flight
       for (int i = 0; i < size - 1; i++) {
           int min = i;
          
           // Search for flight flightList[j] which is comparatively smaller than flightList[i]
           for (int j = i + 1; j < size; j++) {
              
               if (comparator.compare(flightList[j], flightList[i]) < 0) {
                   // Set min as j
                   min = j;
               }
           }
          
           // Swap if flightList[i], flightList[j] if a new min is found
           if (min != i) {
               Flight temp = new Flight();
               // Copy flightList[i] to temp
               temp.copy(flightList[i]);
              
               // Copy flightList[min] to flightList[i]
               flightList[i].copy(flightList[min]);
              
               // Copy temp to flightList[min]
               flightList[min] = temp;
           }
       }
   }
}

import java.io.Serializable;
import java.util.Arrays;

public class FlightManagement implements Serializable {

   // Attributes
   private Flight[] flightList; // an array of Flight objects
   private int currentFlightsCount; // the number of Flight objects created and
                                       // stored in the flightList
   private int maxSize; // the maximum number of Flight objects that can be
                           // stored in the flightList array

   /**
   * Constructor
   */
   public FlightManagement(int maximumsize) {
       // initialize the member variable maxSize
       this.maxSize = maximumsize;

       // instantiate an array of Flight objects
       this.flightList = new Flight[this.maxSize];

       // initialize currentFlightsCount
       this.currentFlightsCount = 0;
   }

   /**
   * Search for a Flight object by airlines and flightNumber, and return the
   * index of the object if found. Returns -1 if not found.
   *
   * @param airlines
   *            - name of the airline
   * @param flightNum
   *            - flight number
   * @return
   */
   public int flightNumberExists(String airlines, int flightNum) {
       int index = -1;

       // Search flight list
       for (int i = 0; i < this.currentFlightsCount; i++) {
           if (this.flightList[i].getAirlines().equalsIgnoreCase(airlines)
                   && (this.flightList[i].getFlightNum() == flightNum)) {
               index = i;
               break;
           }
       }

       return index;
   }

   /**
   * Search for Flight objects in the flight list that have the same departure
   * city, year, month, date, and time as the parameter values and return the
   * index of such object if found. Returns -1 if not found.
   *
   * @param depCity
   *            - departure city
   * @param depYear
   *            - departure year
   * @param depMonth
   *            - departure month
   * @param depDate
   *            - departure date
   * @param depTime
   *            - departure time
   * @return
   */
   public int departureExists(String depCity, int depYear, int depMonth, int depDate, String depTime) {
       int index = -1;

       // Search flight list
       for (int i = 0; i < this.currentFlightsCount; i++) {
           if (this.flightList[i].getDeparture().getCity().equalsIgnoreCase(depCity)
                   && (this.flightList[i].getDeparture().getYear() == depYear)
                   && (this.flightList[i].getDeparture().getMonth() == depMonth)
                   && (this.flightList[i].getDeparture().getDate() == depDate)
                   && this.flightList[i].getDeparture().getTime().equalsIgnoreCase(depTime)) {

               index = i;
               break;
           }
       }

       return index;
   }

   /**
   * Add a Flight object to the flight list and return true if such object was
   * added successfully. Returns false if an object with the same airlines,
   * flight number, departure city, year, month, date, and time already exists
   * or currentFlightsCount is already same as maxSize
   *
   * @param airlines
   *            - name of the airline
   * @param flightNum
   *            - flight number
   * @param depCity
   *            - departure city
   * @param depYear
   *            - departure year
   * @param depMonth
   *            - departure month
   * @param depDate
   *            - departure date
   * @param depTime
   *            - departure time
   * @param arrCity
   *            - arrival city
   * @param arrYear
   *            - arrival year
   * @param arrMonth
   *            - arrival month
   * @param arrDate
   *            - arrival date
   * @param arrTime
   *            - arrival time
   * @return
   */
   public boolean addFlight(String airlines, int flightNum, String depCity, int depYear, int depMonth, int depDate,
           String depTime, String arrCity, int arrYear, int arrMonth, int arrDate, String arrTime) {

       // Check if array is not full
       if (this.currentFlightsCount < this.maxSize) {

           // Check if the flight already exists
           boolean found = false;
           for (int i = 0; i < this.currentFlightsCount; i++) {
               if (this.flightList[i].getAirlines().equalsIgnoreCase(airlines)
                       && (this.flightList[i].getFlightNum() == flightNum)
                       && (this.flightList[i].getDeparture().getCity().equalsIgnoreCase(depCity))
                       && (this.flightList[i].getDeparture().getYear() == depYear)
                       && (this.flightList[i].getDeparture().getMonth() == depMonth)
                       && (this.flightList[i].getDeparture().getDate() == depDate)
                       && (this.flightList[i].getDeparture().getTime().equalsIgnoreCase(depTime))) {

                   found = true;
                   break;
               }
           }

           // If not found add to the list
           if (!found) {
               // Create a flight object
               Flight flight = new Flight();
               flight.setAirlines(airlines);
               flight.setFlightNum(flightNum);
               flight.setArrival(arrCity, arrYear, arrMonth, arrDate, arrTime);
               flight.setDeparture(depCity, depYear, depMonth, depDate, depTime);

               this.flightList[this.currentFlightsCount] = flight;
               this.currentFlightsCount += 1;
               return true;
           }
       }

       return false;
   }

   /**
   * Remove a Flight object from the flight list. Return true if the object
   * was removed successfully. Return false if the object with the given
   * airlines and flight number does not exist.
   *
   * @param airlines
   *            - name of the airline
   * @param flightNum
   *            - flight number
   */
   public boolean removeFlightNumber(String airlines, int flightNum) {

       // Get index of flight with airlines and flightNum
       int index = flightNumberExists(airlines, flightNum);

       if (index != -1) {
           // Move flight after index one position up
           for (int i = index + 1; i < this.currentFlightsCount; i++) {
               this.flightList[i - 1] = this.flightList[i];
           }
           this.flightList[this.currentFlightsCount - 1] = null;
           this.currentFlightsCount -= 1;
          
           return true;

       } else
           return false;
   }

   /**
   * Sorts the list of Flight objects by airlines and flight number. This
   * method calls the sort method defined in the Sorts class, using an object
   * of FlightNumberComparator class as its second parameter.
   */
   public void sortByFlightNumber() {
       // Create FlightNumberComparator object
       FlightNumberComparator comparator = new FlightNumberComparator();

       // Sort list
       Sorts.sort(this.flightList, this.currentFlightsCount, comparator);
   }

   /**
   * Sort the list of Flight objects by their departure information including
   * its city, year, month, date, and time. This method calls the sort method
   * defined in the Sorts class, using an object of DepartureComparator class
   * as its second parameter.
   */
   public void sortByDeparture() {
       // Create DepartureComparator object
       DepartureComparator comparator = new DepartureComparator();

       // Sort list
       Sorts.sort(this.flightList, this.currentFlightsCount, comparator);
   }

   /**
   * List all Flight objects in the flight list.
   *
   * @return
   */
   public String listFlights() {
       StringBuffer sb = new StringBuffer();

       // If list is empty
       if (this.currentFlightsCount == 0)
           sb.append(" No flight ");
       else {
           for (int i = 0; i < this.currentFlightsCount; i++) {
               sb.append(this.flightList[i].toString());
           }
       }

       return sb.toString();
   }

   /**
   * Closes the flight management system by making the list empty.
   */
   public void closeFlightManagement() {

       // Empty flight list array
       Arrays.fill(this.flightList, null);
      
       // Set count to 0
       this.currentFlightsCount = 0;

   }
}

For Assignment8 class

                   case 'U': // Write Text to a File
                       System.out.print("Please enter a file name to write: ");
                       filename = stdin.readLine().trim();
                      
                       PrintWriter pw = null;
                       try {
                           // Create PrintWriter object
                           pw = new PrintWriter(new File(filename));
                          
                           // Get contents from the user
                           System.out.print("Please enter a string to write in the file: ");
                           String contents = stdin.readLine().trim();
                          
                           // Write to the file
                           pw.print(contents + " ");
                           pw.flush();
                          
                           System.out.println(filename + " was written ");
                       } catch (IOException ioe) {
                           System.out.println(ioe.getMessage());
                          
                       } finally {
                           // Close writer
                           if (pw != null)
                               pw.close();
                       }
                      
                       break;
                   case 'V': // Read Text from a File
                       System.out.print("Please enter a file name to read: ");
                       filename = stdin.readLine().trim();

                       // Scanner to read from the file
                       Scanner file = null;
                      
                       try {
                           file = new Scanner(new File(filename));
                           System.out.println(filename + " was read ");
                           System.out.println("The first line of the file is: ");
                           // Read the first line from the file
                           System.out.println(file.nextLine() + " ");
                          
                       } catch (FileNotFoundException fnfe) {
                           System.out.println(filename + " was not found ");
                          
                       } finally {
                           // Close scanner
                           if (file != null)
                               file.close();
                       }
                      
                       break;
                   case 'W': // Serialize FlightManagement to a File
                       System.out.print("Please enter a file name to write: ");
                       filename = stdin.readLine().trim();
                      
                       // Create output stream to write object to the file
                       ObjectOutputStream oos = null;
                       try {
                           // Create ObjectOutputStream object
                           oos = new ObjectOutputStream(new FileOutputStream(new File(filename)));
                          
                           // Write each flight to the file
                           oos.writeObject(manage1);
                          
                           System.out.println(filename + " was written ");
                       } catch (NotSerializableException nse) {
                           System.out.println("Flight management object not serializale");
                          
                       } catch (IOException ioe) {
                           System.out.println(ioe.getMessage());
                          
                       } finally {
                           // Close writer
                           if (oos != null)
                               oos.close();
                       }
                      
                       break;
                   case 'X': // Deserialize FlightManagement from a File
                       System.out.print("Please enter a file name to read: ");
                       filename = stdin.readLine().trim();

                       // Create output stream to read object from the file
                       ObjectInputStream ois = null;
                       try {
                           // Create ObjectInputStream object
                           ois = new ObjectInputStream(new FileInputStream(new File(filename)));
                          
                           // Read object from the file
                           manage1 = (FlightManagement)ois.readObject();
                          
                           System.out.println(filename + " was read ");
                       } catch (ClassNotFoundException cnfe) {
                           System.out.println("Flight management object not found in the file");
                          
                       } catch (FileNotFoundException fnfe) {
                           System.out.println(filename + " was not found ");
                          
                       } catch (IOException ioe) {
                           System.out.println(ioe.getMessage());
                          
                       } finally {
                           // Close reader
                           if (ois != null)
                               ois.close();
                       }
                      
                       break;
                   case '?': // Display Menu