Question: Planet.java package planets; /** * Represents a planet in the solar system */ class Planet implements Comparable { private final String name; private final double

Planet.java
package planets; /** * Represents a planet in the solar system */ class Planet implements Comparable { private final String name; private final double mass; private final int distance; /** * Creates a new planet * * @param name The name of the planet * @param mass The mass of the planet in 10^24 kg * @param distance The average distance from the sun in 10^6 km */ public Planet(String name, double mass, int distance) { this.name = name; this.mass = mass; this.distance = distance; } @Override public int compareTo(Planet other) { // TODO return 0; } public String getName() { return name; } public double getMass() { return mass; } public int getDistance() { return distance; } @Override public String toString() { return "Planet{" + "name=" + name + ", mass=" + mass + ", distance=" + distance + '}'; } }
PlanetsMain.java
package planets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * Prints facts about planets - practice using Collections methods */ public class PlanetsMain { public static void main(String[] args) { // Source https:/ssdc.gsfc.nasa.gov/planetary/factsheet/ List planets = new ArrayList(9); planets.add(new Planet("Mercury", 0.33, 58)); planets.add(new Planet("Venus", 4.87, 108)); planets.add(new Planet("Earth", 5.97, 150)); planets.add(new Planet("Mars", .642, 228)); planets.add(new Planet("Jupiter", 1898, 779)); planets.add(new Planet("Saturn", 568, 1434)); planets.add(new Planet("Uranus", 86.8, 2873)); planets.add(new Planet("Neptune", 102, 4495)); planets.add(new Planet("Pluto", 0.0146, 5906)); System.out.println("Orignal order:"); printPlanets(planets); // Randomize the order of the planets // TODO System.out.println("Planets in a random order:"); printPlanets(planets); // Remove pluto // TODO System.out.println("Removed Pluto:"); printPlanets(planets); // Sort by distance from sun using Natural Ordering (Hint: Implement Planet.compareTo) System.out.println("Sorted by distance from sun:"); printPlanets(planets); // Sort alphabetically (Hint: you need a Comparator class) // TODO System.out.println("Sorted alphabetically:"); printPlanets(planets); // Sort by mass (Hint: you need a Comparator class) // TODO System.out.println("Sorted by mass:"); printPlanets(planets);
// Add each planet in your list to a Map (name => Planet) Map planetMap = new HashMap(); // Hint - use an enhanced for loop // TODO System.out.println("Earth:" + planetMap.get("Earth")); // Retrieve and print Mars // TODO } /** * Print the planet list in a table */ private static void printPlanets(List planets) { System.out.println("------------------------------------------------------------"); System.out.printf("%-10s%-15s%-10s%n%n", "Planet", "Mass", "Distance"); for (Planet planet : planets) { System.out.printf("%-10s%-15.3f%-10d%n", planet.getName(), planet.getMass(), planet.getDistance()); } System.out.println("------------------------------------------------------------ \ n"); } }
The science museum wants to create an exhibit about the planets in our solar system. Your job is to design a display that shows facts about the planet in various ways. Download the starter code and fill in the TODOs to make the application display the correct information about each planet ordering. The science museum wants to create an exhibit about the planets in our solar system. Your job is to design a display that shows facts about the planet in various ways. Download the starter code and fill in the TODOs to make the application display the correct information about each planet ordering