Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help modifying the doSimulation ( ) method below I've included the rest of the assingment for context. Here is a class diagram showing
I need help modifying the doSimulation method below I've included the rest of the assingment for context. Here is a class diagram showing the attributes and operations of your system. Following the diagram, is a table describing the purpose of the operations listed. You should understand the class diagram and operations descriptions before starting to code. ClassEnum Method Name Description FlightOps initializeFlightList Reads in a sample flight list into a LinkedList from a CSV file. ReadCSVWithScanner LinkedListgetFlightListFromCSVString filePath Reads in a sample flight list into a LinkedList from a CSV file. FlightOps void doSimuluation Driver method for airport operations simulation initializes the LinkedList, modifies statuses randomly, and then processes the status changes, modifying the LinkedList as necessary FlightsOps void changeStatuses Changes statuses from default Scheduled to random values FlightOps void removeCancelledFlights Removes flights with statuses causes cancellation of flight FlightOps void printFlights Prints a list of flights in the LinkedList FlightOps void moveQueuedFlights Flights with status Queued should be moved to the end of the LinkedList FlightOps void presidentAndCroniesJumpTheQueue President and cronies jump to the front of the list on demand. Sample of Linked List Methods you will likely find useful. Use as many of these as you can: addLast; addFirst; addFlight e indexOfObject o getFirst getLast; peek; peekLast; poll or remove pollLast; peekLast; addindex element Preliminary Instructions: Download and extract the provided stubbed out project zip file Download Download and extract the provided stubbed out project zip fileinto your IdeaProjects home directory. Open the project. This project will compile but is incomplete. Your job will be to correct it Note that a provided Flights.csv CommaDelimitedValue file is located in the resources directory under your src directory in IntelliJ. Take a look at this file. There is also a file called Employees.csv in this directory, which is provided so you can practice using an external file in a program. ReadCSVFromScannerEmployee has a main method and you can run ReadCSVFromScannerEmployee from your project. Just open this source file and select the second Run menu and you will be able to pick which Runnable to execute. This will load and print out the data in the Employees.csv file. See the Tutorial on CSV files in Unit so that you understand how to use CSV files. If this works correctly, you should not have trouble with the Flights.csv file. Examine the Flight class in the project. Modify the class ReadCSVWithScanner patterning your code from the ReadCSVFromScannerEmployee class. Your modified class should be able to read and process the Flights.CSV file without errors. Test it successfully before proceeding. Modify the doSimulation method in the provided FlightOps class file where indicated: Most of the code for this assignment is already provided for you. Several methods from the FlightOps class called below are stubbed out in the project file provided and will require you to supply needed code where indicated. You will need to complete the printFlights method, and add the appropriate LinkedList methods addFirst addLast add and remove where appropriate. What happens in DoSimulation The method initializeFlightList builds a LinkedList of flights with a default status of Scheduled. The method changeStatuses is then called to set the statuses of the status to a random status to make our operations more interesting. Certain statuses make sense only for arrivals or departures. Examine the setOperationStatus and understand how it works. OperationStatuses that will result in a flight cancellation are identified and those flights are removed from the list. The operation uses the remove method. The president and his cronies can jump the queue, ThreeVIP flights are created and added to the list. You are welcome to add more. Finally, flights with the status of Queued are moved to the bottom of the LinkedList using the addLast method. Note that we cannot simply use fornext loops to remove or move items within the loop, since that would affect the the list that we are looping through and create a concurrency exception. We therefore, use a Stack to keep track of items to be removed or moved while going through the for loop, then in a separate loop popping them off the stack to do the remove operation. This is the whole FlightOps.java file: import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.LinkedList; import java.util.Stack; public class FlightOps LinkedList flts new LinkedList; private void printFlights for Flight f : flts System.out.printlntoString ftoString; private void removeCancelledFlights Stack removeStack new Stack; Remove flights with cancellation statuses, use stack to avoid concurrency problem with fornext for Flight flt: flts if fltoperationStatus Flight.OperationStatus.CancelDueCrash fltoperationStatus Flight.OperationStatus.CancelDueDrunkPilot fltoperationStatus Flight.OperationStatus.CancelDueMaintenance fltoperationStatus Flight.OperationStatus.CancelDuePassengerDisturbance fltoperationStatus Flight.OperationStatus.NavigationError fltoperationStatus Flight.OperationStatus.CancelNoPlane removeStack.pushflt; while removeStack.isEmpty fltsremoveremoveStackpop; Change statuses from default Scheduled to a random status. Some statuses make sense only for Arrival or Departure so FlightType is checked before setting private void changeStatuses for Flight flt : flts Flight.OperationStatus status FlightOperationStatus Flight.OperationStatus.getRandomStatus; if fltflightType Flight.FlightType.Arrival if status Flight.OperationStatus.CancelDueCrash status Flight.OperationStatus.NavigationError status Flight.OperationStatus.Scheduled status Flight.OperationStatus.Queued fltsetOperationStatusstatus; if status doesn't make sense, don't set it else if fltflightType Flight.FlightType.Arrival && status Flight.OperationStatus.CancelDueMaintenancefltflightType Flight.FlightType.Departure && status Flight.OperationStatus.NavigationError continue; else fltsetOperationStatusstatus; Move flights with Queued status to end of LinkedList private void moveQueuedFlights Stack moveStack new Stack; for Flight flt : flts Use a stack to move items to be removed Items can't be removed from within fornext because loop will hit a concurrency exception if fltoperationStatus Flight.OperationStatus.Queued moveStack.pushflt; Now we use the stack to move the items to end while moveStack.isEmpty Save this item before removing Flight flight Flight moveStack.peek; Now remove it fltsremovemoveStackpop; Add your code here add flight to bottom of LinkedList see addLast method private void presidentAndCroniesJumpTheQueue President and his cronies jump the line SimpleDateFormat sdf new SimpleDateFormatMMddyy HH:mm; try Date date sdfparse:; Date date sdfparse:; Date date sdfparse:; Flight vipFlight new FlightVipAFCDG date Flight.FlightType.Departure; Flight vipFlight new FlightVipAFCDG date Flight.FlightType.Departure; Flight vipFlight new FlightVipAFCDG date Flight.FlightType.Arrival; Add your code here to add the above three flights to the top of the LinkedList See addFirst method Add your code here to add the above three flights to the top of the LinkedList See addFirst method catch ParseException e System.out.printlnDate Parse Exception"; public void doSimuluationString filePath flts initializeFlightListfilePath; changeStatuses; System.out.printlnChanged statuses"; printFlights; System.out.printlnRemove cancelled flights"; removeCancelledFlights; printFlights; presidentAndCroniesJumpTheQueue; System.out.printlnCronies jump queue"; printFlights; moveQueuedFlights; System.out.printlnMoved queued flights"; printFlights; public static void mainString args FlightOps fltOPs new FlightOps; String filePath resourcesFlightscsv; fltOPs.doSimuluationfilePath; public LinkedList initializeFlightListString filePath Load flights from external file ReadCSVWithScanner csvReader new ReadCSVWithScanner; LinkedList fltList csvReader.getFlightListFromCSVfilePath; return fltList;
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