-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSongObjectClass
214 lines (193 loc) · 5.06 KB
/
SongObjectClass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
public class SongObjectClass
{
private String songName;
private String artistName;
private double length;
private String genre;
/**
* Constructor for objects of class SongObjectClass
*/
public SongObjectClass(String pSongName, String pArtistName, double pLength, String pGenre)
{
songName = pSongName;
artistName = pArtistName;
length = pLength;
genre = pGenre;
}
// getter methods
public String getSongName()
{
return songName;
}
public String getArtistName()
{
return artistName;
}
public double getLength()
{
return length;
}
public String getGenre()
{
return genre;
}
// setter methods
public void newSong(String nSong)
{
songName = nSong;
}
public void newArtist(String nArtist)
{
artistName = nArtist;
}
public void newLength(double duration)
{
length = duration;
}
public void newGenre(String nGenre)
{
genre = nGenre;
}
public void play()
{
Scanner scan = new Scanner(System.in);
System.out.println("What are the lyrics of the song?");
String lyrics = scan.nextLine();
System.out.println("Do you want to play the song?");
String answer = scan.nextLine();
if (answer.equalsIgnoreCase("yes") || answer.equalsIgnoreCase("y"))
{
System.out.println("Playing " + songName + " by " + artistName + ".");
System.out.println(lyrics);
}
}
public void songDescription()
{
System.out.println("The name of this song is " + songName + ", written by " + artistName +
". It has a length of " + length + " minute(s), and the genre is " + genre + ".");
}
public void createPlaylist(int playlistLength)
{
String playlist = "";
Scanner scan = new Scanner(System.in);
for (int i = 0; i < playlistLength; i++)
{
System.out.println("What song do you want to add?");
String first = scan.nextLine();
playlist = playlist + first + ", ";
}
System.out.println("Your playlist consists of the songs " + playlist);
}
public static void totalLength(SongObjectClass s1, SongObjectClass s2)
{
double total = s1.length + s2.length;
System.out.println("The duration of these two songs combined is: " + total);
}
public static void checkGenre(SongObjectClass... g1)
{
boolean allDifferent = true;
int count1 = 0;
int count2 = 0;
for (SongObjectClass s1: g1)
{
count2++;
for (SongObjectClass s2: g1)
{
if (s1.genre.equals(s2.genre))
{
count1++;
}
}
}
if (count1 > count2)
{
System.out.println("Not all songs are unique.");
}
else
{
System.out.println("All songs are unique");
}
}
public static double randomLength()
{
double l = (Math.random()*6);
if (l < 1)
{
l = l + 1;
}
return l;
}
public static String randomGenre()
{
int g = (int)(Math.random()*10);
String rGenre = "";
if (g == 1)
{
rGenre = "Pop";
}
else if (g == 2)
{
rGenre = "Blues";
}
else if (g == 3)
{
rGenre = "R&B";
}
else if (g == 4)
{
rGenre = "Indie";
}
else if (g == 5)
{
rGenre = "Rock";
}
else if (g == 6)
{
rGenre = "Soul";
}
else if (g == 7)
{
rGenre = "Dance";
}
else if (g == 8)
{
rGenre = "Classical";
}
else if (g == 9)
{
rGenre = "Jazz";
}
return rGenre;
}
static String artist = "";
public static String rArtist()
{
String alphabet = "abcdefghijklmnopqrstuvwxyz";
String rName = "";
for (int i = 0; i < alphabet.length(); i++)
{
int rIndex = (int)(Math.random()*26);
rName = rName + alphabet.substring(rIndex, rIndex + 1);
}
rName = rName.substring(0, (int)(Math.random()*7));
artist = rName;
return rName;
}
public static String rSong()
{
String alphabet = "abcdefghijklmnopqrstuvwxyz";
String rS = "";
for (int i = 0; i < alphabet.length(); i++)
{
int rIndex = (int)(Math.random()*26);
rS = rS + alphabet.substring(rIndex, rIndex + 1);
}
rS = rS.substring(0, (int)(Math.random()*7));
return rS;
}
public String read()
{
return "The name of this song is " + this.rSong() + " by " + artist +
" that is " + this.randomLength() + " minutes long, and its genre is " + this.randomGenre() + ". ";
}
}