Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Basic Java Questions. Help, please! Use the class CelestialBody and the interface Orbits to answer the question parts 1-7. public class CelestialBody { private double
Basic Java Questions. Help, please!
Use the class CelestialBody and the interface Orbits to answer the question parts 1-7.
public class CelestialBody
{
private double mass; // in kg
private double velocity;
private String name;
public CelestialBody(double mass, double velocity, String name)
{
this.mass = mass;
this.velocity = velocity;
this.name = name;
}
public double mass() { return mass; }
public double velocity() { return velocity; } public String name() { return name; }
}
public interface Orbits
{
public double duration();
public CelestialBody orbiting(); }
1. Write a class Planet that extends CelestialBody and implements Orbits. The constructor should take the mass, velocity, name, orbital duration, the celestial body being orbited, and an integer number of moons. Write the entire class. Each field of the Planet should have a way to be queried.
2.Override the equals() method from Object in both CelestialBody and Planet. Indicate which method should go in which class.
3. Assume a Moon and Star class also extend CelestialBody and implement Orbits. Further assume that a class Asteroid extends CelestialBody. Finally assume that the CelestrialBody class implements a method struckBy() that takes an Asteroid as its input parameter. Draw a UML diagram of all the described classes and interfaces (including Planet).
Create a Comparator object, where larger masses should come first. Do this in 3 different ways 1) By writing a separate class, 2) By using a Lambda expression, and 3) By using a key extractor.
5. Complete the following method that returns the total orbital duration of all the CelestialBodies in the input ArrayList. Note that not all the objects in the list orbit something. These objects should contribute nothing to the total.
public double totalDuration(ArrayList spaceThings) { write here}
6. Write a method that accepts a List of Planet objects and returns a list of all Planet objects with masses between 50% and 200% of the mass of the earth (5.9736x1024kg). Use a Stream.
7. Write a method that accepts a Map>. Each Map entry represents a planet and all celestial bodies that orbit that planet. The method also accepts a CelestialBody object and will return a List of all the Planet objects that are orbited by the CelestialBody.
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