Skip to content

Commit f76c59d

Browse files
authored
Merge branch 'code-differently:main' into main
2 parents 636c494 + 61847f3 commit f76c59d

File tree

15 files changed

+845
-0
lines changed

15 files changed

+845
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package com.codedifferently.lesson16.ezranyabuti;
2+
3+
import java.util.ArrayList;
4+
5+
public class Party {
6+
7+
private String name;
8+
private String location;
9+
private String localDate;
10+
private Boolean isPrivate;
11+
private double coverCharge;
12+
private int ticketNumber;
13+
private Vibe vibe;
14+
private ArrayList<String> guestList;
15+
16+
public Party(
17+
String name,
18+
String location,
19+
String localDate,
20+
Boolean isPrivate,
21+
Double coverCharge,
22+
int ticketNumber,
23+
Vibe vibe,
24+
String[] guestList) {
25+
this.name = name;
26+
this.location = location;
27+
this.isPrivate = isPrivate;
28+
this.coverCharge = coverCharge;
29+
this.ticketNumber = ticketNumber;
30+
this.vibe = vibe;
31+
this.guestList = new ArrayList<>();
32+
}
33+
34+
public String getName() {
35+
return name;
36+
}
37+
38+
public void setName(String name) {
39+
this.name = name;
40+
}
41+
42+
public String getLocation() {
43+
return location;
44+
}
45+
46+
public void setLocation(String location) {
47+
this.location = location;
48+
}
49+
50+
public String getLocalDate() {
51+
return localDate;
52+
}
53+
54+
public void setLocalDate(String localDate) {
55+
this.localDate = localDate;
56+
}
57+
58+
public Boolean getIsPrivate() {
59+
return isPrivate;
60+
}
61+
62+
public void setIsPrivate(Boolean isPrivate) {
63+
this.isPrivate = isPrivate;
64+
}
65+
66+
public double getCoverCharge() {
67+
return coverCharge;
68+
}
69+
70+
public void setCoverCharge(double coverCharge) {
71+
this.coverCharge = coverCharge;
72+
}
73+
74+
public int getTicketNumber() {
75+
return ticketNumber;
76+
}
77+
78+
public void setTicketNumber(int ticketNumber) {
79+
this.ticketNumber = ticketNumber;
80+
}
81+
82+
public Vibe getVibe() {
83+
return vibe;
84+
}
85+
86+
public void setVibe(Vibe vibe) {
87+
this.vibe = vibe;
88+
}
89+
90+
public ArrayList<String> getGuestList() {
91+
ArrayList<String> copy = new ArrayList<>();
92+
for (String guest : guestList) {
93+
copy.add(guest);
94+
}
95+
return copy;
96+
}
97+
98+
public void setGuestList(ArrayList<String> guestList) {
99+
this.guestList = guestList;
100+
}
101+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.ezranyabuti;
2+
3+
public class PartyCityException extends Exception {
4+
public PartyCityException(String message) {
5+
super(message);
6+
}
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.codedifferently.lesson16.ezranyabuti;
2+
3+
public enum Vibe {
4+
CHILL,
5+
PRIVATE,
6+
ALL_WHITE,
7+
RELAXED_LOUNGE,
8+
COSTUME
9+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.codedifferently.lesson16.rmillcamera;
2+
3+
import java.util.ArrayList;
4+
5+
public class Camera {
6+
private String brand;
7+
private int megapixels;
8+
private double price;
9+
private ArrayList<String> supportedFormats;
10+
private CameraMode mode;
11+
12+
public Camera(String brand, int megapixels, double price, CameraMode mode) {
13+
this.brand = brand;
14+
this.megapixels = megapixels;
15+
this.price = price;
16+
this.mode = mode;
17+
this.supportedFormats = new ArrayList<>();
18+
}
19+
20+
public void addFormat(String format) throws CameraException {
21+
if (format == null || format.isEmpty()) {
22+
throw new CameraException("Format cannot be empty.");
23+
}
24+
supportedFormats.add(format);
25+
System.out.println("Added format: " + format);
26+
}
27+
28+
public void showFormats() {
29+
if (supportedFormats.isEmpty()) {
30+
System.out.println("No formats supported yet.");
31+
} else {
32+
System.out.println("Supported formats:");
33+
for (String format : supportedFormats) {
34+
System.out.println("- " + format);
35+
}
36+
}
37+
}
38+
39+
public void isAffordable(double budget) {
40+
String result =
41+
(price <= budget) ? "This camera is within your budget." : "This camera is too expensive.";
42+
System.out.println(result);
43+
}
44+
45+
public static void main(String[] args) {
46+
try {
47+
Camera myCamera = new Camera("Sony", 24, 899.99, CameraMode.PORTRAIT);
48+
49+
myCamera.addFormat("JPEG");
50+
myCamera.addFormat("RAW");
51+
52+
myCamera.showFormats();
53+
myCamera.isAffordable(1000);
54+
55+
} catch (CameraException e) {
56+
System.out.println("Error: " + e.getMessage());
57+
}
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.rmillcamera;
2+
3+
public class CameraException extends Exception {
4+
public CameraException(String message) {
5+
super(message);
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.codedifferently.lesson16.rmillcamera;
2+
3+
public enum CameraMode {
4+
AUTO,
5+
MANUAL,
6+
PORTRAIT,
7+
NIGHT
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.tiktokvideosystem;
2+
3+
public class InvalidViewIncrementException extends RuntimeException {
4+
public InvalidViewIncrementException(String message) {
5+
super(message);
6+
}
7+
}
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.codedifferently.lesson16.ezranyabuti;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
public class PartyExceptionTest {
8+
@Test
9+
void testConstructor() {
10+
String expectedMessage = "Party is not private";
11+
PartyCityException exception = new PartyCityException(expectedMessage);
12+
String actualMessage = exception.getMessage();
13+
assertThat(actualMessage).isEqualTo(expectedMessage);
14+
}
15+
}

0 commit comments

Comments
 (0)