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.
Location.java file. Note that the getters, setters, and custom methods for this class are done, as is the constructor for initializing the
Sally left you a
TODO comment with instructions for coding a second constructor:
- It should call the first constructor to initialize the
- It must also initialize the
valuefield for a new
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
value fields, but NOT for
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 for
Want to use fewer clicks? You could always Generate getters and setters for both
value, and then delete the
Be careful, though. If you forget to remove
setID, then users can change the
id value, which may cause problems in the program.
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 the
- Use the Generate option again to add the
hashCodemethods. 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
push your work up to GitHub.