Program Planet Record Sorting Sorting is one of the most common applications of
ID: 3801940 • 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 from files and formatting output. Specification In this assignment, you will implement a planet information sorter program. Your program must include the following elements: l. 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, year Discovered. mass, radius orbit Period An example file is shown below: TrES-2b, 2006, 1.197, 1.247, 2.47 HAT-P-7b, 2008, 1.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:Explanation / Answer
Answer:
Here is Planet.java:
------------------------------------------------------------------------------------------------------------------------------------------
This is the driver program containing the main() method:
PlanetRecordTest.java
-----------------------------------------------------------------------------------------------------------------------------------------------
OUTPUT:
Planet sorting program by Your_Name
Please enter name of file containing planet records:planetRecord.txt
Please enter attribute of records on which to sort:
yearDiscovered
Name Discovered Mass Radius Orbit
TrES-2b 2006 1.197 1.247 2.470
HAT-P-7b 2008 1.781 1.419 2.204
Kepler-4b 2010 0.077 0.357 3.213
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.