Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help as soon as possible thank you! A Tweet Create a new class called Tweet which will hold a single tweet. a tweet has

Need help as soon as possible thank you!

A Tweet

Create a new class called Tweet which will hold a single tweet.

a tweet has a timestamp, an author, and text

the timestamp is an object of type LocalDateTime

the author is a String, which starts with @

the text is a String which can contain any characters, and might contain hashtags, which start with #; there can be multiple hashtags and they can appear anywhere in the text of the tweet

tweet needs methods for the following:

a constructor to initialize all fields of a tweet

toString, which returns a nicely formatted version of the tweet

methods necessary to check the date of a tweet, the author of a tweet, and whether a tweet contains a given hashtag; these methods should have a date, author, or hashtag as a parm, and should return boolean to tell whether the parm matches the data in the tweet (we are trying to avoid get and set methods whenever possible)

All of the Tweets

Create a new class called AllTweets which will hold all the Tweets. The AllTweets class will use an unorderedList to hold the Tweets, and will have methods for the following:

add a Tweet

toString, to create a nicely formatted display of all the tweets

method to find all tweets written by the given author, and return them as a new AllTweets object

method to find all tweets written on the given date, and return them as a new AllTweets object

method to find all tweets containing the given hashtag, and return them as a new AllTweets object

method to find all tweets written between two dates (inclusive) and return them as a new AllTweets object

method to find all tweets by a given author on a given date, return them as a new AllTweets object

method to remove all tweets written by a given author and return them as a new AllTweets object

method to remove all tweets written by a given author on a given date and return them as a new AllTweets object

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 screenandto 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==>

Timestamps

For timestamps we will use the LocalDateTime and LocalDate classes from the Java API. Look up these classes; you may find the documentation somewhat confusing; that's fine, but it's important to get used to looking up Java classes.

These classes provide methods to create, print, and compare dates. Here is the information you need to work with these objects in your program.

To read and write these dates we need to describe the date format to read or print. To do so, we use a DateTimeFormatter object. (Look up this class too.) The DateTimeFormatter object can be created to use whatever date format you choose.

Reading Dates

To read dates of the form (date and time, separated by the character T):

2016:02:18T17:24:56

We will read it as a String, then create a DateTimeFormatter, using the ISO_LOCAL_DATE_TIME format. Then we use the parse method of the LocalDateTime class to create the LocalDateTime object. Assume that strtime is a String containing the date and time:

LocalDateTime timestamp;

DateTimeFormatter format = DateTimeFormatter.ISO_LOCAL_DATE_TIME;

timestamp = LocalDateTime.parse(strtime, format);

To read dates of the form (date only):

2016:02:18

We will read it as a String, then create a DateTimeFormatter using the ISO_LOCAL_DATE format. Then we use the parse method for LocalDate to create the LocalDate object. Assume that date is a String containing the date:

DateTimeFormatter format = DateTimeFormatter.ISO_LOCAL_DATE;

LocalDate datestamp = LocalDate.parse(date, format);

Printing Dates

To print a LocalDateTime object we will create a DateTimeFormatter with the SHORT formatstyle for both the date and the time. We will use the format() method of the LocalDateTime object to create a String representation of the LocalDateTime object timestamp:

DateTimeFormatter formatter

= DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT,FormatStyle.SHORT);

String strout = timestamp.format(formatter);

This will print a LocalDateTime as

2/18/15 5:24 PM

Comparing Dates

When we compare dates, we will compare only the dates, not the dates and times. Thus we need to compare two LocalDate objects, using the equals method of the LocalDate class. A LocalDateTime object is converted to a LocalDate object using the toLocalDate method. Assume that timestamp is a LocalDateTime object:

LocalDate justDate = timestamp.toLocalDate();

and two LocalDate objects can be compared using equals or compareTo.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Entrepreneurship

Authors: Andrew Zacharakis, William D Bygrave

5th Edition

1119563097, 9781119563099

More Books

Students also viewed these Programming questions