Task 2: Create the Support Classes
Sally needs you to build up the remaining classes. In each case, refer to the Employer class for hints on how to structure your code.
The Location Class
Open the Location.java file. Note that the getters, setters, and custom methods for this class are done, as is the constructor for initializing the id field.
Sally left you a TODO comment with instructions for coding a second constructor:
- It should call the first constructor to initialize the
idfield. - It must also initialize the
valuefield for a newLocationobject.
The CoreCompetency Class
Open the class file. In this case, the constructors and custom methods are ready. Sally needs you to complete the somewhat tedious task of writing the getters and setters for the id and value fields, but NOT for nextID.
Fortunately, IntelliJ has a tool to help with this:
- Right-click in the editor pane and select Generate.
- Select the Getter and Setter option.
- Select the
valueoption, then click OK. you should now see the getters and setters. - Since the unique value of
idis set with the constructors, we only need to add a getter for this field. Select Generate again and use the Getter option forid.
Want to use fewer clicks? You could always Generate getters and setters for both id and value, and then delete the setID method.
Be careful, though. If you forget to remove setID, then users can change the id value, which may cause problems in the program.
The PositionType Class
Open the class file. This time the constructors, getters, and setters are done. Sally’s comments direct you to where you need to add the custom methods.
- Code a
toStringmethod that just returns thevalueof aPositionTypeobject. - Use the Generate option again to add the
equalsandhashCodemethods. Refer to the Classes and Objects Part 2 IntelliJ Generator Shortcut section if you need a quick review. - Assume that two
PositionTypeobjects are equal when their id fields match.
Now would be a good time to save, commit, and push your work up to GitHub.