Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 implements ListInterface {

private listNode head; private listNode tail; private int length; private listNode current; private listNode preNode;

// 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 newNode = new listNode(item); tail.successor = newNode; tail = newNode; length++; }

// 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 curr = find(element); if (curr != null) return true; return false; }

// returns a list item that matches element public T get(T element) { listNode curr = find(element); if (curr != null) return curr.getElement(); return null; }

// Returns a nicely formatted string that represents this list. public String toString() { String result = "The list: "; listNode curr = head; while (curr != null) { result = result + " " + curr.getElement() + " "; curr = curr.getSuccessor(); } return result; }

// private method to find the node that contains item // return the node or null if not found private listNode find(T item) { listNode curr = head; while (curr != null && !curr.getElement().equals(item)) { curr = curr.getSuccessor(); } if (curr != null) return curr; return null; }

}

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

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_2

Step: 3

blur-text-image_3

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

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions