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:

  1. It should call the first constructor to initialize the id field.
  2. It must also initialize the value field for a new Location 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:

  1. Right-click in the editor pane and select Generate.
  2. Select the Getter and Setter option.
  3. Select the value option, then click OK. you should now see the getters and setters.
  4. 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 for id.
Note

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.

  1. Code a toString method that just returns the value of a PositionType object.
  2. Use the Generate option again to add the equals and hashCode methods. Refer to the Classes and Objects Part 2 IntelliJ Generator Shortcut section if you need a quick review.
  3. Assume that two PositionType objects are equal when their id fields match.
Tip

Now would be a good time to save, commit, and push your work up to GitHub.

Next