import java.util.ArrayList

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

import java.util.ArrayList;

/**
 * This class describes a user of Twitter. A user has a user ID 
 * (e.g. @testudo), a list of tweets, a count of the number of followers,
 * and a list of users that this user follows.  Unlike P5,
 * there is no upper limit on the number of tweets or users to follow.
 * 
 * You may NOT import any library class other than java.util.ArrayList.
 * You may NOT add any instance variables to keep a count of the number
 * of tweets or users being followed. You may add instance variables
 * for other purposes as long as they are private.
 */
public class TwitterUser {
    
    private String userID;
    private int followers;
    private ArrayList<Tweet> listTweets;
    private ArrayList<TwitterUser> toFollow;
    
    /**
     * A constructor that takes the user's ID. If the ID is null, or
     * longer than 32 characters, or it does not start with "@",
     * throw an IllegalArgumentException.
     * 
     * All other instance variables should be initialized appropriately.
     * 
     * @param userID the ID of the new user
     */
    public TwitterUser(String userID) {
        if(userID == null || userID.length() > 32) { //if userID is null
             throw new IllegalArgumentException("User ID is null");
         }
         
         this.userID = userID;
         this.followers = followers;
         this.listTweets = new ArrayList<>();
         this.toFollow = new ArrayList<>();
    }
    
    /**
     * A pseudo copy-constructor that takes an existing user, a new userID,
     * and a boolean flag. It should create a new user with the newID given 
     * (which has the same restrictions as above), and the same tweets as the 
     * old user that is being passed in. Information about the number of 
     * followers or list of users the old user is following should NOT be copied.
     * If the flag is false, make a shallow copy of the old user's tweet ArrayList, 
     * otherwise make a deep copy. Never make a reference copy.
     * All other instance variables should be initialized appropriately.
     * It may help you to call the earlier constructor here.
     * 
     * @param old
     * @param newID
     */
    public TwitterUser(TwitterUser old, String newID, boolean flag) {
        if (flag == true) {
            this.userID = newID;
            this.listTweets = old.listTweets;
            this.toFollow = old.toFollow;
        }
    }
    
    /** 
     * Creates a new Tweet object using the given message and adds it 
     * to this user's list of tweets. 
     * 
     * Note: If the String passed in is null OR if the tweet is 
     * longer than Tweet.MAX_LENGTH, then this method will not 
     * add anything to the list and simply return false. 
     * It will return true if it was able to add to the list.
     * 
     * @param message the message of the tweet
     * @return true if the tweet was added to the list, false otherwise
     */
    public boolean tweet(String message) {
        throw new UnsupportedOperationException();
    }
    
    /**
     * Adds all the tweets in the given list to this user's list.
     * A 1-line solution exists (see ArrayList API).
     * 
     * @param tweets the list of tweets to be tweeted
     * @return true if atleast one tweet was added, false otherwise
     */
    public boolean tweetAll(ArrayList<Tweet> tweets) {
        throw new UnsupportedOperationException();
    }
    
    /**
     * This method allows the user to retweet an already existing tweet.
      * You may have to make appropriate changes in the Tweet object.
      * Do not make a deep copy of the Tweet object, just point to it
      * directly.
     * 
     * @param t the Tweet Object to be retweeted
     * @return true 
     */
    public boolean retweet(Tweet t) {
        throw new UnsupportedOperationException();
    }
    
    /** 
     * This method retweets all the tweets of the TwitterUser object
     * that is passed in. Do not make a deep copy of the Tweets.
     * 
     * @param u the TwitterUser whose tweets are to be retweeted
     * @return true 
     */
    public boolean retweetAll(TwitterUser u) {
        throw new UnsupportedOperationException();
    }
    
    /**
     * Like all the tweets of the TwitterUser that is passed in. It would
     * be a good idea to look at the like() method of the Tweet class.
     * There is no true/false return because a like is always successful.
     * 
     * @param u the TwitterUser whose tweets are to be liked
     */
    public void likeAll(TwitterUser u) {
        throw new UnsupportedOperationException();
    }
    
    /**
     * 
     * @return the number of tweets this user has tweeted or retweeted
     */
    public int getNumTweets() {
        throw new UnsupportedOperationException();
    }

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Array
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