Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. /**
  2. * Represents (and constructs) a single RAT object.
  3. *
  4. * @author Kathryn Swint
  5. * @version 12/05/2019
  6. */
  7.  
  8. import java.util.LinkedList;
  9.  
  10. public class RAT
  11. {
  12. // instance variables - replace the example below with your own
  13. protected String username;
  14. protected String userID;
  15. protected long tweetCount;
  16. protected long storyCount;
  17. protected LinkedList<String> stories;
  18.  
  19. /**
  20. * Constructor for objects of class RAT
  21. */
  22. public RAT(String u, String uID, long t, long s)
  23. {
  24. this.username = u;
  25. this.userID = uID;
  26. this.tweetCount = t;
  27. this.storyCount = s;
  28. stories = new LinkedList<String>();
  29. }
  30.  
  31. /**
  32. * Adds a story to the RAT's LinkedList of stories.
  33. *
  34. * @param story the story to be added
  35. */
  36. protected void addStory(String story) {
  37. try {
  38. if (!stories.contains(story)) {
  39. stories.add(story); //avoiding adding duplicate stories
  40. }
  41. } catch (NullPointerException ex) {
  42. System.out.println(ex + " for story " + story);
  43. }
  44. }
  45.  
  46. /**
  47. * Creates a nicely formatted string representation of a RAT object.
  48. *
  49. * @return a string representation of a RAT object
  50. */
  51. public String toString() {
  52. String allStories = "";
  53. for (String s : stories) {
  54. allStories += s + ", ";
  55. }
  56. allStories = allStories.substring(0, allStories.length()-3); //removes the last "," and space
  57. return username + "\t" + userID + "\t"
  58. + tweetCount + "\t" + storyCount + "\t" + allStories; //nicely formatted string
  59. }
  60.  
  61. public static void main(String[] args) {
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement