-
Notifications
You must be signed in to change notification settings - Fork 25
feat: Added Zion's Movie Object and Test to lesson_16 #528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cfdb19d
feat: Added Zion's Bedroom Object and Test to lesson_16
zionbuch 763424d
fix: naming errors
zionbuch ac65838
Merge branch 'code-differently:main' into lesson_16
zionbuch 5b31569
feat: added Zion's Movie Object and Test to lesson_16 hw
zionbuch 43c7166
Merge branch 'lesson_16' of https://github.com/zionbuch/code-differen…
zionbuch 36dff74
Merge branch 'code-differently:main' into lesson_16
zionbuch fd8880c
feix: Mresolved changes
zionbuch d0c7838
feat: made changes to Zions Movie Folder for lesson_16
zionbuch d70085b
Merge branch 'code-differently:main' into lesson_16
zionbuch ca0b09d
Merge branch 'code-differently:main' into lesson_16
zionbuch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
...objects_app/src/main/java/com/codedifferently/lesson16/lunch/InvalidCalorieException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.codedifferently.lesson16.lunch; | ||
|
||
public class InvalidCalorieException extends Exception { | ||
public InvalidCalorieException(String message) { | ||
super(message); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/lunch/Lunch.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.codedifferently.lesson16.lunch; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class Lunch { | ||
|
||
public enum LunchType { | ||
VEGETARIAN, | ||
NON_VEGETARIAN, | ||
VEGAN, | ||
GLUTEN_FREE | ||
} | ||
|
||
// Member variables | ||
private final String mainDish; // String type | ||
private final String sideDish; // String type | ||
private final int calories; // Integer type | ||
private final LunchType lunchType; // Enum type | ||
private final ArrayList<String> drinks; // Collection type (ArrayList) | ||
|
||
// Constructor | ||
public Lunch(String mainDish, String sideDish, int calories, LunchType lunchType) | ||
throws InvalidCalorieException { | ||
if (calories <= 0) { | ||
throw new InvalidCalorieException("Calories cannot be zero or negative."); | ||
} | ||
this.mainDish = mainDish; | ||
this.sideDish = sideDish; | ||
this.calories = calories; | ||
this.lunchType = lunchType; | ||
this.drinks = new ArrayList<>(); | ||
} | ||
|
||
// Member function to add a drink | ||
public void addDrink(String drink) { | ||
drinks.add(drink); | ||
} | ||
|
||
// Member function to get a healthy message based on calories | ||
public String getHealthMessage() { | ||
return (calories < 500) ? "This lunch is healthy!" : "This lunch is high in calories."; | ||
} | ||
|
||
// Member function to display all drinks | ||
public void displayDrinks() { | ||
|
||
System.out.println("Available drinks:"); | ||
for (String drink : drinks) { | ||
System.out.println("- " + drink); | ||
} | ||
} | ||
|
||
// Getters for member variables (optional) | ||
public String getMainDish() { | ||
return mainDish; | ||
} | ||
|
||
public String getSideDish() { | ||
return sideDish; | ||
} | ||
|
||
public int getCalories() { | ||
return calories; | ||
} | ||
|
||
public LunchType getLunchType() { | ||
return lunchType; | ||
} | ||
|
||
public ArrayList<String> getDrinks() { | ||
return drinks; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/movie/Genres.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.codedifferently.lesson16.movie; | ||
|
||
public enum Genres { | ||
DRAMA, | ||
COMEDY, | ||
ACTION, | ||
THRILLER, | ||
HORROR, | ||
SCIENCE_FICTION, | ||
FANTASY, | ||
ROMANCE, | ||
ADVENTURE, | ||
MYSTERY; | ||
} |
89 changes: 89 additions & 0 deletions
89
lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/movie/Movie.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.codedifferently.lesson16.movie; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class Movie { | ||
zionbuch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// member variables | ||
private String title; | ||
private int releaseYear; | ||
private double rating; | ||
private final Genres genres; | ||
private final MovieRating movieRating; | ||
private ArrayList<String> actors; | ||
|
||
// constructor | ||
public Movie( | ||
String title, int releaseYear, double rating, MovieRating movieRating, Genres genres) { | ||
this.title = title; | ||
this.releaseYear = releaseYear; | ||
this.rating = rating; | ||
this.movieRating = movieRating; | ||
this.genres = genres; | ||
this.actors = new ArrayList<String>(); | ||
} | ||
|
||
// getters and setters member functions | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public String setTitle() { | ||
return "Creed 2"; | ||
} | ||
|
||
public int getReleaseYear() { | ||
return releaseYear; | ||
} | ||
|
||
public int setReleaseYear(int releaseYear) { | ||
return this.releaseYear = releaseYear; | ||
} | ||
|
||
public double getRating() { | ||
return rating; | ||
} | ||
|
||
public double setRating(double rating) { | ||
return this.rating = rating; | ||
} | ||
|
||
public Genres getGenres() { | ||
return genres; | ||
} | ||
|
||
public MovieRating getMovieRating() { | ||
return movieRating; | ||
} | ||
|
||
// Conditional | ||
public String goodRating() { | ||
if (rating >= 7.0) { | ||
return "The movie is not good"; | ||
} else { | ||
return "The movie is satisfactory"; | ||
} | ||
} | ||
|
||
public void addActor(String actor) { | ||
actors.add(actor); | ||
} | ||
|
||
public String getActors() throws actorNotAvailableException { | ||
if (actors.isEmpty()) { | ||
throw new actorNotAvailableException("actors not available"); | ||
} | ||
String names = ""; | ||
for (String actor : actors) { | ||
names += actor + ","; | ||
} | ||
return names; | ||
} | ||
} | ||
|
||
class actorNotAvailableException extends Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
public actorNotAvailableException(String message) { | ||
super(message); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
..._16/objects/objects_app/src/main/java/com/codedifferently/lesson16/movie/MovieRating.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.codedifferently.lesson16.movie; | ||
|
||
public enum MovieRating { | ||
zionbuch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
G, | ||
PG, | ||
PG_13, | ||
R; | ||
} |
55 changes: 55 additions & 0 deletions
55
...on_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/movie/MovieTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.codedifferently.lesson16.movie; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class MovieTest { | ||
Movie movie; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
movie = new Movie("Creed", 2015, 7.6, MovieRating.PG_13, Genres.ACTION); | ||
} | ||
|
||
@Test | ||
void testGetMovieTitle() { | ||
// act | ||
String title = movie.getTitle(); | ||
// assert | ||
assertEquals("Creed", title); | ||
} | ||
|
||
@Test | ||
void testSetMovieTitle() { | ||
// arrange | ||
// act | ||
String title = movie.setTitle(); | ||
// assert | ||
assertEquals("Creed 2", title); | ||
} | ||
|
||
@Test | ||
void testGetReleaseYear() { | ||
int releaseYear = movie.getReleaseYear(); | ||
assertEquals(2015, 2015); | ||
} | ||
|
||
@Test | ||
void testSetReleaseYear() { | ||
int releaseYear = movie.setReleaseYear(2018); | ||
assertEquals(movie.getReleaseYear(), 2018); | ||
} | ||
|
||
@Test | ||
void testGetRating() { | ||
double rating = movie.getRating(); | ||
assertEquals(movie.getRating(), 7.6); | ||
} | ||
|
||
@Test | ||
void testGetGenres() { | ||
assertEquals(Genres.ACTION, movie.getGenres()); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably didn't mean to leave this here given the tests.