Question: or example, the following code snippet should produce the output in the comments. Suppose that tweets stores a list of Strings : [ A
or example, the following code snippet should produce the output in the comments. Suppose that tweets stores a list of Strings :
A tweet about something controversial", "Remember to vote!", "Look at this meme :O
Think about how to get the next tweet from the list of tweets, and how you can cycle around to the start once you've gone through all the tweets!
Special Case!
As you're working on your TweetBot and testing your implementation, you'll likely start thinking about different cases that your TweetBot will need to handle. There is one specific special case whose behavior is particularly tricky, so we wanted to talk about it more in depth.
Consider the case where your TweetBot is storing a sequence of tweets, and you call nextTweet on your TweetBot times. Then, you immediately afterward add another tweet before calling nextTweet again. On the next call to nextTweet your TweetBot should return the tweet that was just added NOT the first tweet.
The pseudocode example below demonstrates this.
Note that the case described here is a tricky one really there are couple of different ways that a TweetBot could reasonably handle this situation. But, since you'll be writing code to pass tests that we provide, we're telling you how you should handle this situation for this assignment!
public void removeTweetString tweet
Removes the given tweet from the tweet list if it is present.
Pay particular attention to making sure that the remove method should preserve the current iteration order of the nextTweet method above. The two pseudocode examples below demonstrate the cases where nextTweet is called after removing a tweet from the tweet list. For more visual representations of these examples, check out the diagrams in the general Twitter Trends specification.
Example :
Example :
In other words, the nextTweet method should continue the iteration through the Tweet list, returning the Tweet immediately following the one that was last returned by nextTweet. Note that it continues with the removed tweet cut out of the cycle.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
