Program Planet Record Sorting Sorting is one of the most common applications of
ID: 3864516 • Letter: P
Question
Program Planet Record Sorting Sorting is one of the most common applications of computer science. Java has built-in sorting methods that allow you to quickly and efficiently sort items in different ways. In this program, you will read in records from a file, sort them based on one of the fields of the records using Java's built-in sorting routines, and then write the sorted list to the console as a table. Things you will learn Creating simple classes Comparators and Java's sorting routines Reading input fromfiles and fomatting output. Specification In this assignment, you will implement a planet information sorter program. Your programmust include the following elements: 1. A class called "Planet" to hold a planet's information. 2. Different comparators to compare the different attributes of planets. Planet records will be specified in a file, one record per line. Each line of the file will have five comma-separted fields with no spaces between them (this is called a csv file). The fields will be planetName, yearDiscovered, mass. radius orbitPeriod, An example file is shown below: TrES 2006, 1 197, 1.247, 2.47 HAT-P-7b, 2008, l 781, 1.419,2.204 Kepler-4b, 2010, 0.077, 0.357, 3.213 The program must take two pieces of input, either as command line arguments, or by prompting the user for input: 1. the name of a file containing planet records. 2. the name of a field (attribute) of the records on which to sort, which must be one of planetName, yearDiscovered, mass, radius, orbitPeriod.Explanation / Answer
#include void fnSortHeap(int[], int); void main() { int i, arr_num_items; int arr[] = {7,10,25,17,23,27,16,19,37,42,4,33,1,5,11}; //total number of items in array. //if you do not provide the exact number you might get unwanted results arr_num_items = 15; //call fnSortHeap function for (arr_num_items - 2) times. for(i=arr_num_items; i>1; i--) { fnSortHeap(arr, i - 1); } //print the sorted array printf(" The Sorted Array ---------------- "); for (i = 0; i =0;o--) { for(i=root;i>=0;i--) { lChild = (2*i)+1; rChild = (2*i)+2; if ((lChild arr_ubound) mChild = lChild; else mChild = rChild; } //swap elements if (arr[i]Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.