Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Final Assignment ( 8 5 points ) Please complete the code to satisfy the following requirements: Create an interface Inhabitable that has one method lifeForm
Final Assignment points
Please complete the code to satisfy the following requirements:
Create an interface Inhabitable that has one method lifeForm that returns void.
Create an abstract CelestialObject class that implements Inhabitable and has an attribute celestialObjectType of type String. The celestialObjectType is set through the constructor. Provide the get for the attribute.
The lifeForm method will print a trace message in this format: name of the current class name of the current method your last name Replace the class and the method with the actual class and method and name where you print the trace. For example: classA function Romano
Create a Planet class that extends CelestialObject class and has the following attributes: planetName string, numberOfMoons integer, PlanetType that can be terrestrial or Jovian celestialObjectType should be hardcoded as the string planet
Provide a constructor for the Planet class, that takes the parameters: planet name, number of moons and type.
Validate the parameters:
If the planetName or the planetType is missing throw an InvalidArgumentException.
If the planetName attribute length is more than char throw an InvalidPlanetNameException checked exception create exception class.
If the planetMoons attribute value is more than throw an InvalidNumberOfMoonsException unchecked exception create exception class.
If the planetType is not terrestrial or Jovian throw an InvalidPlanetTypeException unchecked exception create exception class.
The checked exception should be thrown all the way to main
For the Planet class:
Create the gets and the sets for the attributes.
Set the numbers and constants for validations in a static initializer block.
Override equals to compare two planet instances, based on the name, moons and type.
Override the associated function for equals
Override ToString to display the class data in the format NAME type moons Example: EARTH terrestrial moons Note the name is capitalized.
COMP Final Exam Page of June
Create a Singleton Planets class that would always return the same instance of the Planets class. It will also return the same List of Planets.
Create a PlanetsMain class with a main that would call the following functions to display the results.
In PlanetsMain, create the following methods using Stream:
Method name
Parameters
Return
Resulting behavior
printAllPlanetsByName
none
List of Planet information
EARTH terrestrial moons
Capitalize the Name
Prints all planet information sorted by the name ascending. Format to output:
List of planets sorted by Name
EARTH terrestrial moons
printAllPlanetsByMoons
none
List of Planet information
EARTH terrestrial moons
Capitalize the Name
Prints all planet information sorted by the number of moons descending. Format to output:
List of planets sorted by Moons
EARTH terrestrial moons
printPlanetsByType
planetType
List of Planets of the required type
Prints the planets of the type provided. If the type is terrestrial print:
Terrestrial planets
Planet
printPlanetMaxMoons
none
Name of planet and no of moons
Prints the info for the planet with the most moons
EARTH terrestrial moons
COMP Final Exam Page of June
In main:
Print your name and student number.
Print how many planets are in the list.
Print the list of planets sorted by name, with title.
Print the list of planets sorted by the number of moons descending, with title.
Print the list of the terrestrial planets, with title.
Print the list of the Jovian planets, with title.
Trigger the types of errors and print a message to prove.
Format your output for readability. Leave one empty line between the sections. Start the section with the title. For example:
Create Unit Tests for the first two methods. Save the unit tests in a tests package marked for tests should be green.
Create the UML class diagram for the requirements and upload it as pdf Optional p
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