Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can you answer the following question in Java, Please? This Program lets you read data from a file then sort it by two different methods.
Can you answer the following question in Java, Please?
This Program lets you read data from a file then sort it by two different methods. One is the builtin sort method, and the other will be your own method that implements a mergeSort algorithm. You will compare the performance of the two implementations.
This program builds a set of classes to sort a linked list of objects in multiple ways and compare the execution time of each type of sort.
Directions Write a class 'WeatherReport', that has the following methods:
Constructor with no parameters. It should create a linked list of 'Temperature' objects which you can use for testing. Each 'Temperature' object should have a City, State, Low Temperature and High Temperature, along with a method 'Differential', that returns the positive difference between the low and high temperature for that object. Dont include any other attributes in your 'Temperature' object.
Constructor with one String parameter the name of a text file with weather information. The file has a header row, then many rows of temperature recordings.
For example:
Average,City,Code,Direction,Full,Maximum,Minimum,Month,Precipitation,WindSpeed,State,Day,Year
Birmingham,BHMAlabama,
Huntsville,HSVAlabama,
This constructor will create a linked list of 'Temperature' objects, one for each row of data in the file. Your project will have the data file weather.txt Download 'weather.txt which you should use for the program.
isSortedByCity this boolean method returns true if the linked list is in sorted order by city, and false otherwise. Calling this method on the list generated by the constructor should return false.
isSortedByHigh this boolean method returns true if the linked list is in sorted order by highest temperature, and false otherwise. Calling this method on the list generated by the constructor should return false.
sortWithCollectionsString by sorts the linked list using Collections.sort The parameter by tells you whether it should be by City or by high temperature.
sortWithMergeString by sorts the linked list using your own merge sort implementation. The parameter by tells you whether it should be by City or by high temperature.
main test your class by writing a main method that creates 'WeatherReport' objects with exactly the same data, and tests each to be sure it is not already sorted. Sort one by calling 'sortWithCollectionsCity 'and the other by calling 'sortWithMergeCity Be sure to time the results of each sort and record the times. Repeat this for sorting by high temperature. Be sure the linked lists really are sorted.
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