Workbook 11.1
From the Java Bootcamp Resources
, launch starter
.
Task 1
Use the position values inside main()
to fill up the Position
enum
with constants.
public enum Position {
}
Task 2
Update the players
field inside Team
to store Position
keys rather than String
.
private Map<String, String> players;
Task 3
Update getPlayer()
to receive a Position
enum constant rather than a String
.
public String getPlayer(String position) <----
Task 4
Update setPlayer()
to receive a Position
enum constant rather than a String
.
public void setPlayer(String position, String player)
The enum type is guaranteed to be one of five constants. So remove the safety mechanisms.
if (!position.equals("SHOOTING_GUARD") || !position.equals("SMALL_FORWARD") || !position.equals("POWER_FORWARD") ... throw new IllegalArgumentException("INVALID POSITION");
Although you should still ensure that a null
doesn't get passed in.
if (position == null) throw new IllegalArgumentException("Position cannot be null");
Task 5
enum constants are implicitly static
and final
. Import every constant into Main
and fill in the main()
method.
Task 6
Import every constant into Game
and fill in the begin()
method.
Associated Course: The Complete Java Development Bootcamp
Related Course: The Complete Spring Boot Development Bootcamp – Become a Java Web Developer
Feedback Summary
4.7
43 students
5
91%
4
2%
3
0%
2
0%
1
7%
Written Reviews
There are no written reviews yet.