Skip to content

Commit d0c7838

Browse files
committed
feat: made changes to Zions Movie Folder for lesson_16
1 parent fd8880c commit d0c7838

File tree

4 files changed

+113
-6
lines changed

4 files changed

+113
-6
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.lunch;
2+
3+
public class InvalidCalorieException extends Exception {
4+
public InvalidCalorieException(String message) {
5+
super(message);
6+
}
7+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.codedifferently.lesson16.lunch;
2+
3+
import java.util.ArrayList;
4+
5+
public class Lunch {
6+
7+
public enum LunchType {
8+
VEGETARIAN,
9+
NON_VEGETARIAN,
10+
VEGAN,
11+
GLUTEN_FREE
12+
}
13+
14+
// Member variables
15+
private final String mainDish; // String type
16+
private final String sideDish; // String type
17+
private final int calories; // Integer type
18+
private final LunchType lunchType; // Enum type
19+
private final ArrayList<String> drinks; // Collection type (ArrayList)
20+
21+
// Constructor
22+
public Lunch(String mainDish, String sideDish, int calories, LunchType lunchType)
23+
throws InvalidCalorieException {
24+
if (calories <= 0) {
25+
throw new InvalidCalorieException("Calories cannot be zero or negative.");
26+
}
27+
this.mainDish = mainDish;
28+
this.sideDish = sideDish;
29+
this.calories = calories;
30+
this.lunchType = lunchType;
31+
this.drinks = new ArrayList<>();
32+
}
33+
34+
// Member function to add a drink
35+
public void addDrink(String drink) {
36+
drinks.add(drink);
37+
}
38+
39+
// Member function to get a healthy message based on calories
40+
public String getHealthMessage() {
41+
return (calories < 500) ? "This lunch is healthy!" : "This lunch is high in calories.";
42+
}
43+
44+
// Member function to display all drinks
45+
public void displayDrinks() {
46+
47+
System.out.println("Available drinks:");
48+
for (String drink : drinks) {
49+
System.out.println("- " + drink);
50+
}
51+
}
52+
53+
// Getters for member variables (optional)
54+
public String getMainDish() {
55+
return mainDish;
56+
}
57+
58+
public String getSideDish() {
59+
return sideDish;
60+
}
61+
62+
public int getCalories() {
63+
return calories;
64+
}
65+
66+
public LunchType getLunchType() {
67+
return lunchType;
68+
}
69+
70+
public ArrayList<String> getDrinks() {
71+
return drinks;
72+
}
73+
}

lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/movie/Movie.java

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.codedifferently.lesson16.movie;
22

3+
import java.util.ArrayList;
4+
35
public class Movie {
46

57
// member variables
@@ -8,6 +10,7 @@ public class Movie {
810
private double rating;
911
private final Genres genres;
1012
private final MovieRating movieRating;
13+
private ArrayList<String> actors;
1114

1215
// constructor
1316
public Movie(
@@ -17,11 +20,12 @@ public Movie(
1720
this.rating = rating;
1821
this.movieRating = movieRating;
1922
this.genres = genres;
23+
this.actors = new ArrayList<String>();
2024
}
2125

2226
// getters and setters member functions
2327

24-
public String getTitle() {
28+
public String getTitle() {
2529
return title;
2630
}
2731

@@ -53,11 +57,33 @@ public MovieRating getMovieRating() {
5357
return movieRating;
5458
}
5559

56-
//Conditional
57-
if MovieRating =< 4 {
58-
return "Title";
59-
}
60-
60+
// Conditional
61+
public String goodRating() {
62+
if (rating >= 7.0) {
63+
return "The movie is not good";
64+
} else {
65+
return "The movie is satisfactory";
66+
}
67+
}
68+
69+
public void addActor(String actor) {
70+
actors.add(actor);
71+
}
72+
73+
public String getActors() throws actorNotAvailableException {
74+
if (actors.isEmpty()) {
75+
throw new actorNotAvailableException("actors not available");
76+
}
77+
String names = "";
78+
for (String actor : actors) {
79+
names += actor + ",";
80+
}
81+
return names;
82+
}
83+
}
6184

85+
class actorNotAvailableException extends Exception {
86+
public actorNotAvailableException(String message) {
87+
super(message);
6288
}
6389
}

lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/movie/MovieTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.codedifferently.lesson16.movie;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
45
import org.junit.jupiter.api.BeforeEach;
56
import org.junit.jupiter.api.Test;
67

0 commit comments

Comments
 (0)