Question
Need help! Create a new class called AllTweets which will hold all the Tweets. The AllTweets class will use an unorderedList to hold the Tweets,
Need help!
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
My UnOrderedList Class
public class unorderedList
private listNode
// initialize the empty list public unorderedList() { tail = null; head = null; length = 0; current = head; }
// add new item at end of list public void add(T item) { listNode
// return the number of elements in the list public int size() { return length; }
// remove item from list public boolean remove(T item) { preNode = head; current = head.getSuccessor();
while (current != tail) { if (current.getElement().equals(item)) { preNode.setSuccessor(current.getSuccessor());
return true; }
preNode = current; current = current.getSuccessor(); }
return false;
}
// set current to first element in list (or null if list is empty) public void reset() { current = head; }
// return current element and move to next element in list // move back to head if there is no next element // assumes list is not null!! public T getNext() { T element = current.getElement(); if (current == tail) current = head; else current = current.getSuccessor(); return element; }
// return true if element is in the list, otherwise return false public boolean contains (T element) { listNode
// returns a list item that matches element public T get(T element) { listNode
// Returns a nicely formatted string that represents this list. public String toString() { String result = "The list: "; listNode
// private method to find the node that contains item // return the node or null if not found private listNode
}
My tweet class
import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.LocalDate; import java.time.format.FormatStyle;
public class Tweets {
private LocalDateTime timeStamp; private String author; private String text;
public Tweets(String time, String author, String text) { this.author = author; this.text = text; DateTimeFormatter format = DateTimeFormatter.ISO_LOCAL_DATE_TIME; timeStamp = LocalDateTime.parse(time, format); }
public boolean isByAuthor(String name) { return author == name; }
public boolean isByAuthorandDate(String name , String date) { DateTimeFormatter format = DateTimeFormatter.ISO_LOCAL_DATE; LocalDate dateStamp4 = LocalDate.parse(date, format); LocalDate date5 = timeStamp.toLocalDate();
return( author== name && dateStamp4.equals(date5)); } public boolean isOnDate(String date) { DateTimeFormatter format = DateTimeFormatter.ISO_LOCAL_DATE; LocalDate dateStamp = LocalDate.parse(date, format); LocalDate date1 = timeStamp.toLocalDate(); return dateStamp.equals(date1); }
public boolean isInBetween(String start, String end) { DateTimeFormatter format = DateTimeFormatter.ISO_LOCAL_DATE; LocalDate dateStamp1 = LocalDate.parse(start, format); LocalDate dateStamp2 = LocalDate.parse(end, format); LocalDate date1 = timeStamp.toLocalDate();
return (dateStamp1.equals(start) && dateStamp2.equals(end)) || (dateStamp1.equals(start) || dateStamp2.equals(end)); }
public boolean hasHashTag(String tag) { return text.toLowerCase().contains(tag.toLowerCase()); }
private static String changeDate(LocalDateTime changeTime) { DateTimeFormatter formatter= DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT,FormatStyle.SHORT); String s = changeTime.format(formatter); return s; } public String toString() { return String.format("Time Stamp: %s Author:%s %s", timeStamp.toString(), author, text); }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started