Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help as soon as possible! Thank you. Twitter Class The Twitter class will c

ID: 3677142 • Letter: N

Question

Need help as soon as possible! Thank you.

Twitter Class

The Twitter class will contain your main method and other functions: it will read the tweets from a file, and present a menu of options for examining and deleting tweets:

Read the name of the input file, open the input file, and read the tweets. Each tweet will have the format: user timestamp text, where user starts with an @, the timestamp has the format yyyy-mm-ddThh:mm:ss, and the text is any text that can contain hashtags, which start with #. There can be multiple hashtags and they can appear anywhere in the text. See below for more information on how to handle timestamps.

Create an output file named "twitter.txt".

Create a loop which presents the user with a menu of choices. The menu will have choices that correspond to the methods of the AllTweets class. For each option, prompt for and read any necessary info, then call the method. After the call print a heading and then print the AllTweets object returned by the call: print the heading and the AllTweets object to the screen and to the output file.

Do not write one large main method. Break this processing into multiple methods.

Sample Menu

Enter the number for the desired option:

   1: print all tweets

   2: get all tweets by the given author

   3: get all tweets written on the given date

   4: get all tweets containing the given hashtag

   5: get all tweets written between the given dates

   6: get all tweets by the given author written on the given date

   7: remove all tweets by a given user

   8: remove all tweets by the given author on the given date

   9: exit

Choice==>

My Alltweets class

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

public class AllTweets {

private List<Tweets> tweets;

public AllTweets() {
tweets = new ArrayList<>();
}

public void addTweet(Tweets t){
tweets.add(t);
}

public AllTweets tweetsByAuthor(String name){
AllTweets allTweets = new AllTweets();
for(int i = 0; i < tweets.size(); ++i){
if(tweets.get(i).isAuthor(name)){
allTweets.addTweet(tweets.get(i));
}
}
return allTweets;
}

public AllTweets tweetsWithHashTag(String tag){
AllTweets allTweets = new AllTweets();
for(int i = 0; i < tweets.size(); ++i){
if(tweets.get(i).hasHashTag(tag)){
allTweets.addTweet(tweets.get(i));
}
}
return allTweets;
}

public AllTweets tweetsOnDate(LocalDateTime date){
AllTweets allTweets = new AllTweets();
for(int i = 0; i < tweets.size(); ++i){
if(tweets.get(i).isOnDate(date)){
allTweets.addTweet(tweets.get(i));
}
}
return allTweets;
}

public AllTweets tweetsInDuration(LocalDateTime start, LocalDateTime end){
AllTweets allTweets = new AllTweets();
for(int i = 0; i < tweets.size(); ++i){
if(tweets.get(i).isInDuration(start, end)){
allTweets.addTweet(tweets.get(i));
}
}
return allTweets;
}

public String toString(){
String ret = "";
for(int i = 0; i < tweets.size(); ++i){
ret += tweets.get(i).toString() + " ";
ret += "=========================================================== ";
}
return ret;
}

}

Explanation / Answer

public static void main(String arg[]){
AllTweets alltweets = new AllTweets();
Scanner sc = new Scanner(System.in);
while(1){
System.out.println("1: print all tweets");
System.out.println("2: get all tweets by the given author");
System.out.println(" 3: get all tweets written on the given date");
System.out.println("4: get all tweets containing the given hashtag");
System.out.println(" 5: get all tweets written between the given dates");
System.out.println("6: get all tweets by the given author written on the given date");
System.out.println("7: remove all tweets by a given user");
System.out.println("8: remove all tweets by the given author on the given date");
System.out.println("9: exit");
int n= sc.nextInt();
String author;
LocalDateTime date;
LocalDateTime start;
LocalDateTime end;
String tag;
switch(n){
case 1:tweets.toString();break;
case 2:System.out.println("Enter author name: ");
   author=sc.next();
   alltweets.tweetsByAuthor(author);
   break;
case 3:System.out.println("Enter Date: ");
   date=sc.next();
   alltweets.tweetsOnDate(date);
   break;
case 4:System.out.println("Enter Date: ");
   tag=sc.next();
   alltweets.tweetsWithHashTag(tag);
   break;
case 5:System.out.println("Enter start date and end date: ");
   author=sc.next();
   end=sc.next();
   alltweets.tweetsInDuration(author,end);
   break;
case 6:System.out.println("Enter author name and date: ");
   start=sc.next();
   end=sc.next();
   alltweets.tweetsInDuration(start,end);
   break;
case 7:System.out.println("Enter author name: ");
   author=sc.next();
   alltweets.removetweetsByAuthor(author);
   break;
case 8:System.out.println("Enter date and author name: ");
   date=sc.next();   author=sc.next();
   alltweets.removetweetsBydateandauthor(date,author);
   break;
case 9:System.out.println("....Stopped ");exit(0);
default:System.out.println("Invaild option you have entered");break;
}

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote