|
2 | 2 |
|
3 | 3 | import java.util.ArrayList;
|
4 | 4 |
|
5 |
| - |
6 |
| - |
7 | 5 | public class TiktokVideo {
|
8 |
| - private String creatorName; |
9 |
| - private int viewsCount; |
10 |
| - private int likesCount; |
11 |
| - private VideoCategory videoCategory; |
12 |
| - private ArrayList<String> commentsList; |
| 6 | + private String creatorName; |
| 7 | + private int viewsCount; |
| 8 | + private int likesCount; |
| 9 | + private VideoCategory videoCategory; |
| 10 | + private ArrayList<String> commentsList; |
13 | 11 |
|
14 |
| - public enum VideoCategory { |
| 12 | + public enum VideoCategory { |
15 | 13 | DANCE,
|
16 | 14 | COMEDY,
|
17 | 15 | VLOG,
|
18 | 16 | 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 |
| -} |
| 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 | + } |
43 | 41 |
|
44 |
| -public double likeToViewRatio() { |
| 42 | + public double likeToViewRatio() { |
45 | 43 | if (viewsCount == 0) {
|
46 |
| - return 0.0; |
| 44 | + return 0.0; |
47 | 45 | }
|
48 | 46 |
|
49 | 47 | int totalLikes = 0;
|
50 |
| -//used chat because I was not sure how to make a ratio within a for loop |
| 48 | + // used chat because I was not sure how to make a ratio within a for loop |
51 | 49 | for (int i = 0; i < likesCount; i++) {
|
52 |
| - totalLikes++; |
| 50 | + totalLikes++; |
53 | 51 | }
|
54 | 52 |
|
55 | 53 | double ratio = (double) totalLikes / viewsCount;
|
56 | 54 | 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)); |
| 55 | + } |
64 | 56 |
|
65 |
| - } |
| 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 | + } |
66 | 64 | }
|
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; |
| 65 | + } |
80 | 66 |
|
81 |
| -} |
82 |
| -} |
83 |
| - |
| 67 | + public void addComments(String comment) { |
84 | 68 |
|
| 69 | + commentsList.add(comment); |
| 70 | + } |
85 | 71 |
|
| 72 | + public String getCreator() { |
| 73 | + return this.creatorName; |
| 74 | + } |
86 | 75 |
|
| 76 | + public void setVideoCategory(VideoCategory videoType) { |
| 77 | + this.videoCategory = videoType; |
| 78 | + } |
87 | 79 |
|
| 80 | + public VideoCategory getVideoCategory() { |
| 81 | + return this.videoCategory; |
| 82 | + } |
88 | 83 |
|
| 84 | + public int getViewsCount() { |
| 85 | + return this.viewsCount; |
| 86 | + } |
| 87 | +} |
0 commit comments