Skip to content

Commit 4cfaa8a

Browse files
committed
Feat: tiktok content creator system
1 parent dbd5296 commit 4cfaa8a

File tree

1 file changed

+91
-0
lines changed
  • lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/tiktokvideosystem

1 file changed

+91
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.codedifferently.lesson16.tiktokvideosystem;
2+
3+
import java.util.ArrayList;
4+
5+
public class TiktokVideo {
6+
private String creatorName;
7+
private int viewsCount;
8+
private int likesCount;
9+
private VideoCategory videoCategory;
10+
private ArrayList<String> commentsList;
11+
12+
public enum VideoCategory {
13+
DANCE,
14+
COMEDY,
15+
VLOG,
16+
TUTORIAL
17+
}
18+
19+
public TiktokVideo(
20+
String creatorName, int viewsCount, int likesCount, VideoCategory videoCategory) {
21+
this.creatorName = creatorName;
22+
this.viewsCount = viewsCount;
23+
this.likesCount = likesCount;
24+
this.videoCategory = videoCategory;
25+
this.commentsList = new ArrayList<>();
26+
}
27+
28+
// One function uses a conditional expression to check if the video has more than a specific
29+
// number of views (e.g., 1 million views).
30+
public void increaseViews(int amount) {
31+
// Use a conditional to check if amount is positive
32+
if (amount > 0) {
33+
// If so, add amount to the views
34+
this.viewsCount += amount;
35+
}
36+
// Else, either print a message or throw an exception
37+
else {
38+
throw new InvalidViewIncrementException("View increase amount must be positive.");
39+
}
40+
}
41+
42+
public double likeToViewRatio() {
43+
if (viewsCount == 0) {
44+
return 0.0;
45+
}
46+
47+
int totalLikes = 0;
48+
// used chat because I was not sure how to make a ratio within a for loop
49+
for (int i = 0; i < likesCount; i++) {
50+
totalLikes++;
51+
}
52+
53+
double ratio = (double) totalLikes / viewsCount;
54+
return ratio;
55+
}
56+
57+
public void displayComments(ArrayList<String> userComments) {
58+
if (userComments == null) {
59+
System.out.println("No comments yet. Be the first to comment!");
60+
} else {
61+
for (int i = 0; i < userComments.size(); i++) {
62+
System.out.println(userComments.get(i));
63+
}
64+
}
65+
}
66+
67+
public void addComments(String comment) {
68+
69+
commentsList.add(comment);
70+
}
71+
72+
public ArrayList<String> getCommentsList() {
73+
return commentsList;
74+
}
75+
76+
public String getCreator() {
77+
return this.creatorName;
78+
}
79+
80+
public void setVideoCategory(VideoCategory videoType) {
81+
this.videoCategory = videoType;
82+
}
83+
84+
public VideoCategory getVideoCategory() {
85+
return this.videoCategory;
86+
}
87+
88+
public int getViewsCount() {
89+
return this.viewsCount;
90+
}
91+
}

0 commit comments

Comments
 (0)