I am having trouble on figuring out how to tackle this test case, below is my code and image one is the test case I am having trouble at(since it will tested automatically, i dont have the testcase.) image two is the main method, plz debug and fix it. Provide the screenshot of the code and output when finsih. import java.util.*; import java.io.*; public class TweetBot { private List tweets; private int index; public TweetBot(List tweets){ if(tweets.size() < 1){ throw new IllegalArgumentException("need contain at least one tweet!"); } this.tweets = new ArrayList<>(tweets); } public int numTweets(){ return tweets.size(); } public void addTweet(String tweet) { tweets.add(tweet); if (tweets.size() == 1) { index = 0; } } public String nextTweet() { if (tweets.size() == 1) { index = 0; return tweets.get(0); } else { if (index == tweets.size()) { index = 0; } String tweet = tweets.get(index); index++; return tweet; } } public void removeTweet(String tweet) { int tweetIndex = tweets.indexOf(tweet); if (tweetIndex == -1) { // Tweet was not found in the list, so the state of the TweetBot should be unchanged return; } tweets.remove(tweetIndex); if (index > tweetIndex) { // If the removed tweet was before the current index, shift the index back by 1 index--; } else if (index == tweets.size()) { // If the current index is now out of bounds, set it to the last index in the list index = tweets.size() - 1; } } public void reset(){ index = 0; } } This is the wrong output I got: A tweet about something controversial Remember to vote! Look at this meme :O A tweet about something controversial Remember to vote! Look at this meme :O Hii, How are everyone? A tweet about something controversial Remember to vote! Look at this meme :O The most frequent word is: a //plz ignore this

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I am having trouble on figuring out how to tackle this test case, below is my code and image one is the test case I am having trouble at(since it will tested automatically, i dont have the testcase.) image two is the main method, plz debug and fix it. Provide the screenshot of the code and output when finsih.

 

import java.util.*;
import java.io.*;

public class TweetBot {

    private List<String> tweets;
    private int index;

    public TweetBot(List<String> tweets){
        if(tweets.size() < 1){
            throw new IllegalArgumentException("need contain at least one tweet!");
        }
        this.tweets = new ArrayList<>(tweets);
    }

    public int numTweets(){
        return tweets.size();
    }
    
    public void addTweet(String tweet) {
        tweets.add(tweet);
        if (tweets.size() == 1) {
            index = 0;
        }
}

    public String nextTweet() {
        if (tweets.size() == 1) {
            index = 0;
            return tweets.get(0);
        } else {
            if (index == tweets.size()) {
                index = 0;
            }
            String tweet = tweets.get(index);
            index++;
            return tweet;
        }
    }

    public void removeTweet(String tweet) {
        int tweetIndex = tweets.indexOf(tweet);
        if (tweetIndex == -1) {
            // Tweet was not found in the list, so the state of the TweetBot should be unchanged
            return;
        }
        tweets.remove(tweetIndex);
        if (index > tweetIndex) {
            // If the removed tweet was before the current index, shift the index back by 1
            index--;
            } else if (index == tweets.size()) {
                // If the current index is now out of bounds, set it to the last index in the list
                index = tweets.size() - 1;
        }
    }

    public void reset(){
        index = 0;
    }
}

This is the wrong output I got:

A tweet about something controversial
Remember to vote!
Look at this meme :O
A tweet about something controversial
Remember to vote!
Look at this meme :O
Hii, How are everyone?
A tweet about something controversial
Remember to vote!
Look at this meme :O
The most frequent word is: a //plz ignore this

nextTweet works correctly even after tweets are added
Failed: Make sure that nextTweet returns the most recently added tweet if there was
previously only a single tweet in the bot. ex. If bot=[t1], nextTweet would return t1. If
addTweet(t1), then nextTweet should return t2, not t1 again ==> expected: <lol hi XD>
but was: <Does this work>
x
Show stacktrace
Transcribed Image Text:nextTweet works correctly even after tweets are added Failed: Make sure that nextTweet returns the most recently added tweet if there was previously only a single tweet in the bot. ex. If bot=[t1], nextTweet would return t1. If addTweet(t1), then nextTweet should return t2, not t1 again ==> expected: <lol hi XD> but was: <Does this work> x Show stacktrace
- import java.util.*;
2 import java.io.*;
3
public class TwitterMain {
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(new File("tweets.txt")); // Make Scanner over tweet file
List<String> tweets = new ArrayList<>();
while (input.hasNextLine()) { // Add each tweet in file to List
tweets.add(input.nextLine());
}
TweetBot bot = new TweetBot (tweets); // Create TweetBot object with list of tweets
System.out.println(bot.nextTweet()); // should print "tweet about something controversial"
System.out.println(bot.nextTweet());
System.out.println(bot.nextTweet());
// should print "Remember to vote!"
// should print "Look at this meme:0"
System.out.println(bot.nextTweet()); // should print "tweet about something controversial" (because the index has wrapped around)
bot.add Tweet ("This is a new tweet!");
System.out.println(bot.nextTweet()); // should print "This is a new
bot.addTweet ("Hii, How are everyone?");
System.out.println(bot.nextTweet()); // should print "Hii, How are everyone?"
bot.removeTweet ("This is a new tweet!");
a new tweet!"
System.out.println(bot.nextTweet());
System.out.println(bot.nextTweet());
System.out.println(bot.nextTweet());
System.out.println(bot.nextTweet());
Twitter Trends trends = new TwitterTrends (bot); // Create TwitterTrends object
Transcribed Image Text:- import java.util.*; 2 import java.io.*; 3 public class TwitterMain { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("tweets.txt")); // Make Scanner over tweet file List<String> tweets = new ArrayList<>(); while (input.hasNextLine()) { // Add each tweet in file to List tweets.add(input.nextLine()); } TweetBot bot = new TweetBot (tweets); // Create TweetBot object with list of tweets System.out.println(bot.nextTweet()); // should print "tweet about something controversial" System.out.println(bot.nextTweet()); System.out.println(bot.nextTweet()); // should print "Remember to vote!" // should print "Look at this meme:0" System.out.println(bot.nextTweet()); // should print "tweet about something controversial" (because the index has wrapped around) bot.add Tweet ("This is a new tweet!"); System.out.println(bot.nextTweet()); // should print "This is a new bot.addTweet ("Hii, How are everyone?"); System.out.println(bot.nextTweet()); // should print "Hii, How are everyone?" bot.removeTweet ("This is a new tweet!"); a new tweet!" System.out.println(bot.nextTweet()); System.out.println(bot.nextTweet()); System.out.println(bot.nextTweet()); System.out.println(bot.nextTweet()); Twitter Trends trends = new TwitterTrends (bot); // Create TwitterTrends object
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 1 images

Blurred answer
Knowledge Booster
Development strategies
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education