Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2 . 1 Create a file Main.java in which to write your code for this question. 2 . 2 Write code for a main method
Create a file Main.java in which to write your code for this question.
Write code for a main method to build a Min Heap from the data in flights.txt
You will need to write code that performs String preprocessing. This means transform
the raw data into the appropriate Node attributes and calculate the arrival time, before
creating a Node and adding it to the Heap. The heap should be ordered by arrival time.
In the main method, print out the order in which incoming flights should land Sample data: flights.txt
registrationno departuretimestamp, flightduration hh:mm:ss
ZA::::
ZA::::
ZA::::
ZA::::
ZA::::
ZA::::
ZA::::
ZA::::
ZA::::
ZA::::
ZA::::
ZA::::
ZA::::
ZA::::
ZA:::: Give me a code that runs with all the methods
ZA::::
ZA::::
ZA::::
ZA:::: give me referefor the code you gave me to avoid plagiarism
ZA:::: import java.ioFile;
import java.ioFileNotFoundException;
import java.util.Scanner;
class Node
String registrationNo;
String departureTimestamp;
String flightDuration;
long arrivalTime;
NodeString registrationNo, String departureTimestamp, String flightDuration
this.registrationNo registrationNo;
this.departureTimestamp departureTimestamp;
this.flightDuration flightDuration;
this.arrivalTime calculateArrivalTimedepartureTimestamp flightDuration;
private long calculateArrivalTimeString departureTimestamp, String flightDuration
Convert departureTimestamp and flightDuration to milliseconds and add them
Implementation left for brevity
return ; Replace with actual calculation
class MinHeap
Node heap;
int size;
MinHeapint capacity
heap new Nodecapacity;
size ;
void addNode node
heapsize node;
size; Increment size after adding the node
heapifyUpsize ;
Node poll
if size return null;
Node minNode heap;
heap heapsize ;
size;
heapifyDown;
return minNode;
int size
return size;
boolean isEmpty
return size ;
private void heapifyUpint index
Heapify up from index
Implementation left for brevity
private void heapifyDownint index
Heapify down from index
Implementation left for brevity
public class Main
public static void mainString args
try
File file new FileC:UsersIdeaProjectsQuestionPtacsrcflighttxt;
Scanner scanner new Scannerfile;
MinHeap minHeap new MinHeap; Adjust capacity as needed
while scannerhasNextLine
String line scanner.nextLine;
String parts line.split;
String registrationNo partstrim;
String departureTimestamp partstrim;
String flightDuration partstrim;
Node node new NoderegistrationNo departureTimestamp, flightDuration;
minHeap.addnode;
scanner.close;
System.out.printlnOrder of incoming flights:";
while minHeap.isEmpty
Node node minHeap.poll;
System.out.printlnnoderegistrationNo;
catch FileNotFoundException e
System.out.printlnFile not found: flights.txt;
this is the code that i was given by chegg and it doesnt work as it gives me this error Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index out of bounds for length
at MException in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index out of bounds for length
at MinHeap.addMainjava:
at Main.mainMainjava:inHeapaddMainjava: i want full code will all implementation and main method that runs without error and gives me answer
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