Skip to content

Commit 642bad6

Browse files
feat: adds Bryana's custom hip hop artist classes and corresponding tests (#512)
* feat: add hip hop artist classes and corresponding tests * feat: refactor HipHopArtist class and remove unused artist classes and tests * chore: corrects namespace for test Signed-off-by: Anthony D. Mays <[email protected]> * chore: corrects namespace for test Signed-off-by: Anthony D. Mays <[email protected]> --------- Signed-off-by: Anthony D. Mays <[email protected]> Co-authored-by: Anthony D. Mays <[email protected]>
1 parent d782c88 commit 642bad6

File tree

2 files changed

+305
-0
lines changed

2 files changed

+305
-0
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package com.codedifferently.lesson16.hiphopArtist;
2+
3+
import java.util.ArrayList;
4+
5+
public class HipHopArtist {
6+
private boolean isAlive;
7+
private String stageName;
8+
private int debutYear;
9+
private double netWorth;
10+
private ArrayList<String> albums;
11+
private Genre genre;
12+
13+
public HipHopArtist(
14+
boolean isAlive,
15+
String stageName,
16+
int debutYear,
17+
double netWorth,
18+
ArrayList<String> albums,
19+
Genre genre) {
20+
this.isAlive = isAlive;
21+
this.stageName = stageName;
22+
this.debutYear = debutYear;
23+
this.netWorth = netWorth;
24+
this.albums = albums;
25+
this.genre = genre;
26+
}
27+
28+
public String checkLegendStatus() {
29+
return debutYear <= 2000
30+
? stageName + " is a legend in the game."
31+
: stageName + " is a modern star.";
32+
}
33+
34+
public void addAlbum(String album) {
35+
albums.add(album);
36+
System.out.println(album + " was added to " + stageName + "'s discography.");
37+
}
38+
39+
public String listAlbums() throws NoAlbumsException {
40+
if (albums.isEmpty()) {
41+
throw new NoAlbumsException(stageName + " has no albums listed.");
42+
}
43+
System.out.println("Albums by " + stageName + ":");
44+
for (String album : albums) {
45+
System.out.println("- " + album);
46+
}
47+
return stageName;
48+
}
49+
50+
public String getBio() {
51+
return stageName
52+
+ " ("
53+
+ genre
54+
+ ") debuted in "
55+
+ debutYear
56+
+ ", is "
57+
+ (isAlive ? "alive" : "deceased")
58+
+ ", and has a net worth of $"
59+
+ netWorth
60+
+ ".";
61+
}
62+
63+
public boolean isAlive() {
64+
return isAlive;
65+
}
66+
67+
public void setAlive(boolean alive) {
68+
isAlive = alive;
69+
}
70+
71+
public String getStageName() {
72+
return stageName;
73+
}
74+
75+
public void setStageName(String stageName) {
76+
this.stageName = stageName;
77+
}
78+
79+
public int getDebutYear() {
80+
return debutYear;
81+
}
82+
83+
public void setDebutYear(int debutYear) {
84+
this.debutYear = debutYear;
85+
}
86+
87+
public double getNetWorth() {
88+
return netWorth;
89+
}
90+
91+
public void setNetWorth(double netWorth) {
92+
this.netWorth = netWorth;
93+
}
94+
95+
public ArrayList<String> getAlbums() {
96+
return albums;
97+
}
98+
99+
public void setAlbums(ArrayList<String> albums) {
100+
this.albums = albums;
101+
}
102+
103+
public Genre getGenre() {
104+
return genre;
105+
}
106+
107+
public void setGenre(Genre genre) {
108+
this.genre = genre;
109+
}
110+
111+
public enum Genre {
112+
RAP,
113+
GANGSTA_RAP,
114+
OLD_SCHOOL,
115+
TRAP,
116+
DRILL,
117+
}
118+
119+
@Override
120+
public String toString() {
121+
return "HipHopArtist{"
122+
+ "isAlive="
123+
+ isAlive
124+
+ ", stageName='"
125+
+ stageName
126+
+ '\''
127+
+ ", debutYear="
128+
+ debutYear
129+
+ ", netWorth="
130+
+ netWorth
131+
+ ", albums="
132+
+ albums
133+
+ ", genre="
134+
+ genre
135+
+ '}';
136+
}
137+
}
138+
139+
class NoAlbumsException extends Exception {
140+
public NoAlbumsException(String message) {
141+
super(message);
142+
}
143+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
package com.codedifferently.lesson16.hiphopArtist;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
6+
import com.codedifferently.lesson16.hiphopArtist.HipHopArtist.Genre;
7+
import java.util.ArrayList;
8+
import org.junit.jupiter.api.Test;
9+
10+
public class HipHopArtistTest {
11+
12+
@Test
13+
public void testCheckLegendStatus() {
14+
// Create a HipHopArtist object
15+
HipHopArtist artist =
16+
new HipHopArtist(true, "Kendrick Lamar", 2012, 75_000_000, new ArrayList<>(), Genre.RAP);
17+
18+
// Check legend status
19+
String expected = "Kendrick Lamar is a modern star.";
20+
String actual = artist.checkLegendStatus();
21+
22+
// Assert the result
23+
assertEquals(expected, actual);
24+
}
25+
26+
@Test
27+
public void testAddAlbum() {
28+
// Create a HipHopArtist object
29+
HipHopArtist artist =
30+
new HipHopArtist(true, "Kendrick Lamar", 2012, 75_000_000, new ArrayList<>(), Genre.RAP);
31+
32+
// Add an album
33+
artist.addAlbum("good kid, m.A.A.d city");
34+
35+
// Check if the album was added
36+
assertTrue(artist.getAlbums().contains("good kid, m.A.A.d city"));
37+
}
38+
39+
@Test
40+
public void testIsAlive() {
41+
// Create a HipHopArtist object
42+
HipHopArtist artist =
43+
new HipHopArtist(true, "Kendrick Lamar", 2012, 75_000_000, new ArrayList<>(), Genre.RAP);
44+
45+
// Check if the artist is alive
46+
boolean expected = true;
47+
boolean actual = artist.isAlive();
48+
49+
// Assert the result
50+
assertEquals(expected, actual);
51+
}
52+
53+
@Test
54+
public void testGetStageName() {
55+
// Create a HipHopArtist object
56+
HipHopArtist artist =
57+
new HipHopArtist(true, "Kendrick Lamar", 2012, 75_000_000, new ArrayList<>(), Genre.RAP);
58+
59+
// Get stage name
60+
String expected = "Kendrick Lamar";
61+
String actual = artist.getStageName();
62+
63+
// Assert the result
64+
assertEquals(expected, actual);
65+
}
66+
67+
@Test
68+
public void testSetAlive() {
69+
// Create a HipHopArtist object
70+
HipHopArtist artist =
71+
new HipHopArtist(true, "Kendrick Lamar", 2012, 75_000_000, new ArrayList<>(), Genre.RAP);
72+
73+
// Set alive status to false
74+
artist.setAlive(false);
75+
76+
// Check if the artist is alive
77+
boolean expected = false;
78+
boolean actual = artist.isAlive();
79+
80+
// Assert the result
81+
assertEquals(expected, actual);
82+
}
83+
84+
@Test
85+
public void testSetStageName() {
86+
// Create a HipHopArtist object
87+
HipHopArtist artist =
88+
new HipHopArtist(true, "Kendrick Lamar", 2012, 75_000_000, new ArrayList<>(), Genre.RAP);
89+
90+
// Set stage name
91+
artist.setStageName("K.Dot");
92+
93+
// Get stage name
94+
String expected = "K.Dot";
95+
String actual = artist.getStageName();
96+
97+
// Assert the result
98+
assertEquals(expected, actual);
99+
}
100+
101+
@Test
102+
public void testGetDebutYear() {
103+
// Create a HipHopArtist object
104+
HipHopArtist artist =
105+
new HipHopArtist(true, "Kendrick Lamar", 2012, 75_000_000, new ArrayList<>(), Genre.RAP);
106+
107+
// Get debut year
108+
int expected = 2012;
109+
int actual = artist.getDebutYear();
110+
111+
// Assert the result
112+
assertEquals(expected, actual);
113+
}
114+
115+
@Test
116+
public void testSetDebutYear() {
117+
// Create a HipHopArtist object
118+
HipHopArtist artist =
119+
new HipHopArtist(true, "Kendrick Lamar", 2012, 75_000_000, new ArrayList<>(), Genre.RAP);
120+
121+
// Set debut year
122+
artist.setDebutYear(2011);
123+
124+
// Get debut year
125+
int expected = 2011;
126+
int actual = artist.getDebutYear();
127+
128+
// Assert the result
129+
assertEquals(expected, actual);
130+
}
131+
132+
@Test
133+
public void testGetNetWorth() {
134+
// Create a HipHopArtist object
135+
HipHopArtist artist =
136+
new HipHopArtist(true, "Kendrick Lamar", 2012, 75_000_000, new ArrayList<>(), Genre.RAP);
137+
138+
// Get net worth
139+
double expected = 75_000_000;
140+
double actual = artist.getNetWorth();
141+
142+
// Assert the result
143+
assertEquals(expected, actual);
144+
}
145+
146+
@Test
147+
public void testSetNetWorth() {
148+
// Create a HipHopArtist object
149+
HipHopArtist artist =
150+
new HipHopArtist(true, "Kendrick Lamar", 2012, 75_000_000, new ArrayList<>(), Genre.RAP);
151+
152+
// Set net worth
153+
artist.setNetWorth(80_000_000);
154+
155+
// Get net worth
156+
double expected = 80_000_000;
157+
double actual = artist.getNetWorth();
158+
159+
// Assert the result
160+
assertEquals(expected, actual);
161+
}
162+
}

0 commit comments

Comments
 (0)