-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTweet.java
More file actions
29 lines (24 loc) · 1.02 KB
/
Tweet.java
File metadata and controls
29 lines (24 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.*;
public class Tweet {
// Class variables to store tweet details
String username;
String message;
long timestamp; //milliseconds
Set<String> likes; // Set to store the usernames of people who liked the tweet
// Constructor to initialize a new tweet with the username and message
public Tweet(String username, String message) {
this.username = username; // Username who posted the tweet
this.message = message; // Message of the tweet
this.timestamp = System.currentTimeMillis(); // Time when the tweet was posted
this.likes = new HashSet<>(); // Makes sure no duplicate users can like the tweet
}
// Method to display the tweet's details
public void displayTweet() {
System.out.println("[" + timestamp + "] @" + username + ": " + message);
System.out.println("Likes: " + likes.size());
}
// Method to add a like to the tweet by a user
public void addLike(String username) {
likes.add(username);
}
}