Skip to content

Commit c0fb902

Browse files
committed
feat: add hip hop artist classes and corresponding tests
1 parent 61847f3 commit c0fb902

File tree

11 files changed

+490
-0
lines changed

11 files changed

+490
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.codedifferently.lesson16.hiphopArtist;
2+
3+
import java.util.ArrayList;
4+
5+
public class DMX {
6+
public static void main(String[] args) {
7+
ArrayList<String> dmxAlbums = new ArrayList<>();
8+
dmxAlbums.add("It's Dark and Hell Is Hot");
9+
dmxAlbums.add("Flesh of My Flesh, Blood of My Blood");
10+
dmxAlbums.add("And Then There Was X");
11+
dmxAlbums.add("The Great Depression");
12+
dmxAlbums.add("Grand Champ");
13+
14+
var dmx =
15+
new HipHopArtist(false, "DMX", 1998, 10000000, dmxAlbums, HipHopArtist.Genre.GANGSTA_RAP);
16+
17+
System.out.println(dmx.getBio());
18+
System.out.println(dmx.checkLegendStatus());
19+
20+
dmx.addAlbum("The Definition of X: Pick of the Litter");
21+
22+
try {
23+
dmx.listAlbums();
24+
} catch (NoAlbumsException e) {
25+
System.out.println("ERROR: " + e.getMessage());
26+
}
27+
28+
System.out.println(dmx);
29+
30+
dmx.setNetWorth(12000000);
31+
System.out.println("Updated net worth: $" + dmx.getNetWorth());
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.codedifferently.lesson16.hiphopArtist;
2+
3+
import java.util.ArrayList;
4+
5+
public class Eminem {
6+
public static void main(String[] args) {
7+
ArrayList<String> EminemAlbums = new ArrayList<>();
8+
EminemAlbums.add("The Slim Shady LP");
9+
EminemAlbums.add("The Marshall Mathers LP");
10+
EminemAlbums.add("The Eminem Show");
11+
EminemAlbums.add("Encore");
12+
EminemAlbums.add("Relapse");
13+
14+
for (String album : EminemAlbums) {
15+
System.out.println(album);
16+
}
17+
var eminem =
18+
new HipHopArtist(true, "Eminem", 1999, 230000000, EminemAlbums, HipHopArtist.Genre.RAP);
19+
System.out.println(eminem.getBio());
20+
System.out.println(eminem.checkLegendStatus());
21+
22+
eminem.addAlbum("The Marshall Mathers LP 2");
23+
24+
try {
25+
eminem.listAlbums();
26+
} catch (NoAlbumsException e) {
27+
System.out.println("ERROR: " + e.getMessage());
28+
}
29+
System.out.println(eminem);
30+
eminem.setNetWorth(250000000);
31+
System.out.println("Updated net worth: $" + eminem.getNetWorth());
32+
}
33+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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 void 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+
}
48+
49+
public String getBio() {
50+
return stageName
51+
+ " ("
52+
+ genre
53+
+ ") debuted in "
54+
+ debutYear
55+
+ ", is "
56+
+ (isAlive ? "alive" : "deceased")
57+
+ ", and has a net worth of $"
58+
+ netWorth
59+
+ ".";
60+
}
61+
62+
public boolean isAlive() {
63+
return isAlive;
64+
}
65+
66+
public void setAlive(boolean alive) {
67+
isAlive = alive;
68+
}
69+
70+
public String getStageName() {
71+
return stageName;
72+
}
73+
74+
public void setStageName(String stageName) {
75+
this.stageName = stageName;
76+
}
77+
78+
public int getDebutYear() {
79+
return debutYear;
80+
}
81+
82+
public void setDebutYear(int debutYear) {
83+
this.debutYear = debutYear;
84+
}
85+
86+
public double getNetWorth() {
87+
return netWorth;
88+
}
89+
90+
public void setNetWorth(double netWorth) {
91+
this.netWorth = netWorth;
92+
}
93+
94+
public ArrayList<String> getAlbums() {
95+
return albums;
96+
}
97+
98+
public void setAlbums(ArrayList<String> albums) {
99+
this.albums = albums;
100+
}
101+
102+
public Genre getGenre() {
103+
return genre;
104+
}
105+
106+
public void setGenre(Genre genre) {
107+
this.genre = genre;
108+
}
109+
110+
public enum Genre {
111+
RAP,
112+
GANGSTA_RAP,
113+
OLD_SCHOOL,
114+
TRAP,
115+
DRILL,
116+
}
117+
118+
@Override
119+
public String toString() {
120+
return "HipHopArtist{"
121+
+ "isAlive="
122+
+ isAlive
123+
+ ", stageName='"
124+
+ stageName
125+
+ '\''
126+
+ ", debutYear="
127+
+ debutYear
128+
+ ", netWorth="
129+
+ netWorth
130+
+ ", albums="
131+
+ albums
132+
+ ", genre="
133+
+ genre
134+
+ '}';
135+
}
136+
}
137+
138+
class NoAlbumsException extends Exception {
139+
public NoAlbumsException(String message) {
140+
super(message);
141+
}
142+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.codedifferently.lesson16.hiphopArtist;
2+
3+
import java.util.ArrayList;
4+
5+
public class JayZ {
6+
7+
public static void main(String[] args) {
8+
ArrayList<String> jayZAlbums = new ArrayList<>();
9+
jayZAlbums.add("Reasonable Doubt");
10+
jayZAlbums.add("The Blueprint");
11+
jayZAlbums.add("The Black Album");
12+
jayZAlbums.add("4:44");
13+
jayZAlbums.add("Watch the Throne");
14+
15+
var jayZ =
16+
new HipHopArtist(true, "Jay-Z", 1996, 1500000000, jayZAlbums, HipHopArtist.Genre.RAP);
17+
18+
System.out.println(jayZ.getBio());
19+
System.out.println(jayZ.checkLegendStatus());
20+
21+
jayZ.addAlbum("Kingdom Come");
22+
23+
try {
24+
jayZ.listAlbums();
25+
} catch (NoAlbumsException e) {
26+
System.out.println("ERROR: " + e.getMessage());
27+
}
28+
29+
System.out.println(jayZ);
30+
31+
jayZ.setNetWorth(1600000000);
32+
System.out.println("Updated net worth: $" + jayZ.getNetWorth());
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.codedifferently.lesson16.hiphopArtist;
2+
3+
import java.util.ArrayList;
4+
5+
public class KanyeWest {
6+
7+
public static void main(String[] args) {
8+
ArrayList<String> kanyeAlbums = new ArrayList<>();
9+
kanyeAlbums.add("The College Dropout");
10+
kanyeAlbums.add("Late Registration");
11+
kanyeAlbums.add("Graduation");
12+
kanyeAlbums.add("My Beautiful Dark Twisted Fantasy");
13+
kanyeAlbums.add("Yeezus");
14+
15+
var kanye =
16+
new HipHopArtist(true, "Kanye West", 2004, 400000000, kanyeAlbums, HipHopArtist.Genre.RAP);
17+
18+
System.out.println(kanye.getBio());
19+
System.out.println(kanye.checkLegendStatus());
20+
21+
kanye.addAlbum("Donda");
22+
23+
try {
24+
kanye.listAlbums();
25+
} catch (NoAlbumsException e) {
26+
System.out.println("ERROR: " + e.getMessage());
27+
}
28+
29+
System.out.println(kanye);
30+
31+
kanye.setNetWorth(500000000);
32+
System.out.println("Updated net worth: $" + kanye.getNetWorth());
33+
}
34+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.codedifferently.lesson16.hiphopArtist;
2+
3+
import java.util.ArrayList;
4+
5+
public class NipseyHussle {
6+
public static void main(String[] args) {
7+
ArrayList<String> nipseyAlbums = new ArrayList<>();
8+
nipseyAlbums.add("South Central State of Mind");
9+
nipseyAlbums.add("The Marathon");
10+
nipseyAlbums.add("Crenshaw");
11+
nipseyAlbums.add("Victory Lap");
12+
13+
for (String album : nipseyAlbums) {
14+
System.out.println(album);
15+
}
16+
var nipsey =
17+
new HipHopArtist(
18+
true, "Nipsey Hussle", 2005, 8000000, nipseyAlbums, HipHopArtist.Genre.GANGSTA_RAP);
19+
System.out.println(nipsey.getBio());
20+
System.out.println(nipsey.checkLegendStatus());
21+
22+
nipsey.addAlbum("The Marathon Continues");
23+
24+
try {
25+
nipsey.listAlbums();
26+
} catch (NoAlbumsException e) {
27+
System.out.println("ERROR: " + e.getMessage());
28+
}
29+
System.out.println(nipsey);
30+
nipsey.setNetWorth(10000000);
31+
System.out.println("Updated net worth: $" + nipsey.getNetWorth());
32+
}
33+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.codedifferently.lesson16.hiphopArtistTest;
2+
3+
import com.codedifferently.lesson16.hiphopArtist.DMX;
4+
import org.junit.jupiter.api.Test;
5+
6+
public class DMXtest {
7+
@Test
8+
public void testDMX() {
9+
DMX.main(new String[0]); // Call the main method of DMX class
10+
}
11+
12+
@Test
13+
public void testDMXCheckLegendStatus() {
14+
DMX.main(new String[0]); // Call the main method of DMX class
15+
}
16+
17+
@Test
18+
public void testDMXAddAlbum() {
19+
DMX.main(new String[0]); // Call the main method of DMX class
20+
}
21+
22+
@Test
23+
public void testDMXListAlbums() {
24+
DMX.main(new String[0]); // Call the main method of DMX class
25+
}
26+
27+
@Test
28+
public void testDMXGetBio() {
29+
DMX.main(new String[0]); // Call the main method of DMX class
30+
}
31+
32+
@Test
33+
public void testDMXGetNetWorth() {
34+
DMX.main(new String[0]); // Call the main method of DMX class
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.codedifferently.lesson16.hiphopArtistTest;
2+
3+
import com.codedifferently.lesson16.hiphopArtist.Eminem;
4+
import org.junit.jupiter.api.Test;
5+
6+
public class Eminemtest {
7+
@Test
8+
public void testEminem() {
9+
Eminem.main(new String[0]); // Call the main method of Eminem class
10+
}
11+
12+
@Test
13+
public void testEminemCheckLegendStatus() {
14+
Eminem.main(new String[0]); // Call the main method of Eminem class
15+
}
16+
17+
@Test
18+
public void testEminemAddAlbum() {
19+
Eminem.main(new String[0]); // Call the main method of Eminem class
20+
}
21+
22+
@Test
23+
public void testEminemListAlbums() {
24+
Eminem.main(new String[0]); // Call the main method of Eminem class
25+
}
26+
27+
@Test
28+
public void testEminemGetBio() {
29+
Eminem.main(new String[0]); // Call the main method of Eminem class
30+
}
31+
32+
@Test
33+
public void testEminemGetNetWorth() {
34+
Eminem.main(new String[0]); // Call the main method of Eminem class
35+
}
36+
}

0 commit comments

Comments
 (0)