Hello everyone, I have some questions about how to properly answer exercise 4 (Bird Watcher), task 3. Below is the context and task 3:
Instructions:
You are an avid bird watcher who keeps track of how many birds have visited your garden in the last seven days.
This is the int array you will be working with:
int birdsPerDay = new int {0, 2, 5, 3, 7, 8, 4};
You have six tasks, all related to the number of birds that visited your garden.
Task 3: Increment today’s count
Implement the BirdWatcher.incrementTodaysCount() method to increment today’s count:
int birdsPerDay = { 2, 5, 0, 7, 4, 1 };
BirdWatcher birdCount = new BirdWatcher(birdsPerDay);
birdCount.incrementTodaysCount();
birdCount.getToday();
// => 2
Note: in task 2, which was successfully completed, today is the last day, i.e., the last value in the int array, which is 4, equivalent to 4 birds. Task 3 asks me to increase today’s count by 1, which would give 5, but I’m not sure how to approach it.
This is the method for task 3:
class BirdWatcher {
private final int birdsPerDay;
public BirdWatcher(int birdsPerDay) {
this.birdsPerDay = birdsPerDay.clone();
}
//task 3 method
public void incrementTodaysCount(){
//my approach
birdsPerDay[birdsPerDay.length - 1];
incrementBird = incrementBird + 1;
}
}
In the comments “my approach,” I posted my answer, but it is not correct. It should be noted that the method does not return values.
Can anyone help me?