Answered step by step
Verified Expert Solution
Link Copied!

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 built-in 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:
1. Constructor with no parameters. It should create a linked list of 8-10 '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.
2. 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
39,Birmingham,BHM,33,1/3/2016,46,32,1,0,4.33,Alabama,3,2016
39,Huntsville,HSV,32,1/3/2016,47,31,1,0,3.86,Alabama,3,2016
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.
3. 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.
4. 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.
5. sortWithCollections(String by) sorts the linked list using Collections.sort(). The parameter by tells you whether it should be by City or by high temperature.
sortWithMerge(String 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.
7. main test your class by writing a main method that creates 4 'WeatherReport' objects with exactly the same data, and tests each to be sure it is not already sorted. Sort one by calling 'sortWithCollections(City) 'and the other by calling 'sortWithMerge(City)'. 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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Demystified

Authors: Andrew Oppel

1st Edition

0072253649, 9780072253641

More Books

Students also viewed these Databases questions

Question

Who is present when I give in to my bad habit?

Answered: 1 week ago