Exercises: Enum Practice
Fork and clone EnumerablePlanets .
Use the Get from Version Control option to open the project in IntelliJ.
In the project, create a data package.
Create a new public enum called
Planets
.
|
|
Before adding any other fields to
Planets
, go toPlanetController
and update the index handler to pass in aModel
class argument (e.g.Model model
).Use
.addAttribute
to add the planet values to the model.In
templates/index
, create a list element and use the template variable you have just defined in the controller to list all of the planet values on the page.Add a
name
field to the planets.- Create a name property to display a non-capitalized version of each of the planet names.
- Add a constructor with the name field and a getter for the field.
Update the template to display the planet names.
Back in the
Planets
enum, add a new field calledyearLength
.The value of each
yearLength
should be the number of earth days of a year on the given planet.- Number of earth days on each planet:
- Mercury: 88
- Venus: 225
- Earth: 365
- Mars: 687
- Jupiter: 4333
- Saturn: 10759
- Uranus: 30687
- Neptune: 60200
- Number of earth days on each planet:
Update the constructor and add a getter for this field.
Change the index template to display a table of each planet name and its year in earth days.
- In
templates/index
, create a table element and add the appropriate bootstrap class. - The table can be styled to your liking.
- Add a message to let the users know what data you are displaying with the
yearLength
field.
- In
If you wish, add another field to
Planets
. You can find plenty of information on NASAs web site .- Update the enum with the new field, including changing the constructor and adding a getter method.
- Add the field to display in the table, with a message if helpful to convey the information or units of measure.