Here is an example of how we would create our own collections prior to Java 9. This first class defines the structure for PlanetCollection. It has the following components:
- A single instance variable
- A one argument constructor
- Mutator/setter method
- Accessor/getter method
- Method to print the object
Here is the code implementing the preceding listed constructor and methods:
public class PlanetCollection { // Instance Variable private String planetName; // constructor public PlanetCollection(String name) { setPlanetName(name); } // mutator public void setPlanetName(String name) { this.planetName = name; } // accessor public String getPlanetName() { return this.planetName; } public void print() { System.out ...