-
Notifications
You must be signed in to change notification settings - Fork 23
feat: adds Chanels objects and class lesson 16 #517
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
100 changes: 100 additions & 0 deletions
100
...16/objects/objects_app/src/main/java/com/codedifferently/lesson16/comedian/Comedians.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,100 @@ | ||
package com.codedifferently.lesson16.comedian; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class Comedians { | ||
private final String fullName; | ||
private final String nationality; | ||
private final String activeYears; | ||
private final List<String> famousWorks; | ||
private final double netWorth; | ||
private final Map<String, Integer> socialMediaFollowers; // e.g., {"Instagram": 1000000} | ||
private final boolean isStillActive; | ||
private final ComedyGenre comedyGenre; | ||
|
||
public enum ComedyGenre { | ||
OBSERVATIONAL, | ||
SATIRE, | ||
IMPROV, | ||
SLAPSTICK, | ||
DARK, | ||
PARODY | ||
} | ||
|
||
public Comedians( | ||
String fullName, | ||
String nationality, | ||
String activeYears, | ||
List<String> famousWorks, | ||
double netWorth, | ||
Map<String, Integer> socialMediaFollowers, | ||
boolean isStillActive, | ||
ComedyGenre comedyGenre) { | ||
this.fullName = fullName; | ||
this.nationality = nationality; | ||
this.activeYears = activeYears; | ||
this.famousWorks = famousWorks; | ||
this.netWorth = netWorth; | ||
this.socialMediaFollowers = socialMediaFollowers; | ||
this.isStillActive = isStillActive; | ||
this.comedyGenre = comedyGenre; | ||
} | ||
|
||
public String getFullName() { | ||
return fullName; | ||
} | ||
|
||
public String getNationality() { | ||
return nationality; | ||
} | ||
|
||
public String getActiveYears() { | ||
return activeYears; | ||
} | ||
|
||
public ComedyGenre getGenre() { | ||
return comedyGenre; | ||
} | ||
|
||
public List<String> getFamousWorks() { | ||
return famousWorks; | ||
} | ||
|
||
public double getNetWorth() { | ||
return netWorth; | ||
} | ||
|
||
public Map<String, Integer> getSocialMediaFollowers() { | ||
return socialMediaFollowers; | ||
} | ||
|
||
public boolean isStillActive() { | ||
return isStillActive; | ||
} | ||
|
||
public void validateNetWorth() throws InvalidNetWorthException { | ||
if (netWorth < 0) { | ||
throw new InvalidNetWorthException("Net worth cannot be negative!"); | ||
} | ||
} | ||
|
||
public String getCareerStatus() { | ||
return isStillActive ? "Still active" : "Retired"; | ||
} | ||
|
||
public void printFamousWorks() { | ||
System.out.println("Famous Works:"); | ||
for (String work : famousWorks) { | ||
System.out.println("- " + work); | ||
} | ||
} | ||
|
||
public int totalFollowers() { | ||
int total = 0; | ||
for (int count : socialMediaFollowers.values()) { | ||
total += count; | ||
} | ||
return total; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...cts_app/src/main/java/com/codedifferently/lesson16/comedian/InvalidNetWorthException.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.comedian; | ||
|
||
public class InvalidNetWorthException extends Exception { | ||
public InvalidNetWorthException(String message) { | ||
super(message); | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
...s/objects_app/src/test/java/com/codedifferently/lesson16/comedianstest/ComediansTest.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,104 @@ | ||
package com.codedifferently.lesson16.comedianstest; | ||
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. Package name is incorrect, should be the same as the class under test. |
||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import com.codedifferently.lesson16.comedian.Comedians; | ||
import com.codedifferently.lesson16.comedian.Comedians.ComedyGenre; | ||
import com.codedifferently.lesson16.comedian.InvalidNetWorthException; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ComediansTest { | ||
|
||
private Comedians testComedian; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
testComedian = | ||
new Comedians( | ||
"Dave Chappelle", | ||
"USA", | ||
"1991–present", | ||
List.of("Killing Them Softly", "Sticks & Stones"), | ||
50000000, | ||
Map.of("Instagram", 1000000, "Twitter", 500000), | ||
true, | ||
ComedyGenre.SATIRE); | ||
} | ||
|
||
@Test | ||
public void testFullName() { | ||
assertEquals("Dave Chappelle", testComedian.getFullName()); | ||
} | ||
|
||
@Test | ||
public void testCareerStatus() { | ||
assertEquals("Still active", testComedian.getCareerStatus()); | ||
} | ||
|
||
@Test | ||
public void testTotalFollowers() { | ||
assertEquals(1500000, testComedian.totalFollowers()); | ||
} | ||
|
||
@Test | ||
public void testFamousWorksSize() { | ||
assertEquals(2, testComedian.getFamousWorks().size()); | ||
} | ||
|
||
@Test | ||
public void testInvalidNetWorthThrowsException() { | ||
Comedians brokeComedian = | ||
new Comedians( | ||
"Test Comic", | ||
"USA", | ||
"2010–present", | ||
List.of("Set A"), | ||
-1000.0, | ||
Map.of("Instagram", 10000), | ||
true, | ||
ComedyGenre.DARK); | ||
|
||
assertThrows(InvalidNetWorthException.class, brokeComedian::validateNetWorth); | ||
} | ||
|
||
@Test | ||
public void testPrintFamousWorksOutput() { | ||
// comments for CH to explain method from chatGPT Set up to capture System.out | ||
ByteArrayOutputStream outContent = new ByteArrayOutputStream(); | ||
PrintStream originalOut = System.out; | ||
System.setOut(new PrintStream(outContent)); | ||
|
||
// Call the method | ||
testComedian.printFamousWorks(); | ||
|
||
// Restore original System.out | ||
System.setOut(originalOut); | ||
|
||
// Expected output (make sure to include newline characters properly) | ||
String expectedOutput = "Famous Works:\n- Killing Them Softly\n- Sticks & Stones\n"; | ||
|
||
// Compare output | ||
assertEquals(expectedOutput, outContent.toString()); | ||
} | ||
|
||
@Test | ||
public void testGetNationality() { | ||
assertEquals("USA", testComedian.getNationality()); | ||
} | ||
|
||
@Test | ||
public void testGetActiveYears() { | ||
assertEquals("1991–present", testComedian.getActiveYears()); | ||
} | ||
|
||
@Test | ||
public void testGetGenre() { | ||
assertEquals(ComedyGenre.SATIRE, testComedian.getGenre()); | ||
} | ||
} |
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.
Should be named
Comedian
singular since it represents a single individual.