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
id
field. - It must also initialize the
value
field for a newLocation
object.
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
value
option, then click OK. you should now see the getters and setters. - Since the unique value of
id
is 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
toString
method that just returns thevalue
of aPositionType
object. - Use the Generate option again to add the
equals
andhashCode
methods. Refer to the Classes and Objects Part 2 IntelliJ Generator Shortcut section if you need a quick review. - Assume that two
PositionType
objects are equal when their id fields match.
Now would be a good time to save
, commit
, and push
your work up to GitHub.