Java Bootcamp – Workbooks and Challenges
)}

Workbook 9.1

From the Java Bootcamp Resources, launch starter.

starter.png

Task 1

The Team class contains two fields.

private String name; private Map<String, String> players;

Fill in the logic for the constructor.

public Team(String name) { // set the name. // set players equal to a new HashMap. }

Task 2

Fill in the logic for the getters and setters

public String getName() { // return the name } public void setName(String name) { // set the name } public String getPlayer(String position) { // return a player from the HashMap. } public void setPlayer(String position, String player) { // Add a <String, String> entry into the HashMap }

Task 3

The Game class contains two fields.

private String arena; private LocalDate date;

The LocalDate class provides the now() method.

public class LocalDate { public static LocalDate now() { return now(Clock.systemDefaultZone()); } }

The static keyword allows you to call the method from the class itself.

LocalDate.now()

Use this information to fill the logic in the Game constructor.

public Game(String arena) { // set the arena. // set the date equal to the current date. }

Task 4

The LocalDate class provides the following methods.

public class LocalDate { public int getYear() { return year; } public int getMonthValue() { return month; } public int getDayOfMonth() { return day; } }

You can invoke these methods from any object of the LocalDate class.

date.getDayOfMonth(); date.getMonthValue(); date.getYear();

Use this information to fill the first line inside begin().

"\n - This matchup takes place at the " + this.arena + " arena on " + "<day/month/year>" + ".";

Execute your code.

>>: - This matchup takes place at the Etihad Stadium arena on 04/01/2023.
>>: ...
>>: ...

Task 5

Task 4 familiarized you with LocalDate getters. In this case, favor calling format.

String formattedDate = this.date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));

Execute your code.

>>: - This matchup takes place at the Etihad Stadium arena on 04/01/2023.
>>: ...
>>: ...

Task 6

Consider that main() already populates two teams with players.

Team bulls = new Team("Chicago Bulls"); bulls.setPlayer("SHOOTING_GUARD", "Michael Jordan"); bulls.setPlayer("SMALL_FORWARD", "Scottie Pippen"); bulls.setPlayer("POWER_FORWARD", "Dennis Rodman"); bulls.setPlayer("CENTER", "Bill Wennington"); bulls.setPlayer("POINT_GUARD", "Randy Brown"); Team pistons = new Team("Detroit Pistons"); pistons.setPlayer("SHOOTING_GUARD", "Joe Dumars"); pistons.setPlayer("SMALL_FORWARD", "Grant Hill"); pistons.setPlayer("POWER_FORWARD", "Otis Thorpe"); pistons.setPlayer("CENTER", "William Bedford"); pistons.setPlayer("POINT_GUARD", "Isiah Thomas");

Use this information to fill the remaining lines inside begin().


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.