forked from Shreerang4/learning-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserpost.java
More file actions
56 lines (49 loc) · 1.2 KB
/
userpost.java
File metadata and controls
56 lines (49 loc) · 1.2 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
public class userpost{
public static void main(String[] args){
User user1 = new User();
user1.username = "TEST";
// Printing Username
System.out.println("username: "+user1.getusr()+"\n");
Post post1 = new Post();
post1.postId = 111;
post1.likes = 100;
post1.comments = 10;
// Printing Post methods
System.out.println("PostID: "+post1.getpid());
System.out.println("PostLikes: "+post1.getpl());
System.out.println("PostComments: "+post1.getpc());
// Liking and commenting
user1.likepost(post1);
user1.commentpost(post1);
// Checking
System.out.println("\nPost Stats after like and comment");
System.out.println("PostLikes: "+post1.getpl());
System.out.println("PostComments: "+post1.getpc());
}
}
class User{
String username;
public String getusr(){
return username;
}
public void likepost(Post post){
post.likes++;
}
public void commentpost(Post post){
post.comments++;
}
}
class Post{
int postId;
int likes;
int comments;
public int getpid(){
return this.postId;
}
public int getpl(){
return this.likes;
}
public int getpc(){
return this.comments;
}
}