Skip to content

Commit 3448743

Browse files
committed
feat: add TikTokVideo class with core features, exceptions, and test file
1 parent faa4f80 commit 3448743

File tree

3 files changed

+106
-0
lines changed

3 files changed

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

0 commit comments

Comments
 (0)