import java.util.*
fun main(args: Array<String>) {
val verwaltung = Musikverwaltung()
val song1 = Song("Led Zeppelin", "Led Zeppelin", 3.0, 90)
val song2 = Song("Led Zeppelin II", "Led Zeppelin", 2.45, 80)
val song3 = Song("Led Zeppelin III", "Led Zeppelin", 4.34, 72)
val song4 = Song("[Led Zeppelin IV]", "Led Zeppelin", 7.52, 85)
val song5 = Song("Houses of the Holy", "Led Zeppelin", 5.53, 94)
val song6 = Song("Physical Graffiti", "Led Zeppelin", 2.54, 100)
val song7 = Song("Presence", "Led Zeppelin", 1.20, 67)
val song8 = Song("In Through the Out Door", "Led Zeppelin", 4.30, 93)
val song9 = Song("Coda", "Led Zeppelin", 2.10, 91)
val song10 = Song("Taylor Swift", "Taylor Swift", 2.45, 87)
val song11 = Song("Fearless", "Taylor Swift", 1.25, 67)
val song12 = Song("Speak Now", "Taylor Swift", 2.37, 53)
val song13 = Song("Red", "Taylor Swift", 2.50, 85)
val song14 = Song("1989", "Taylor Swift", 3.50, 96)
val song15 = Song("reputation", "Taylor Swift", 1.30, 68)
val song16 = Song("One of the Boys", "Katy Perry", 2.50, 67)
val song17 = Song("Teenage Dream", "Katy Perry", 2.35, 87)
val song18 = Song("PRISM", "Katy Perry", 1.23, 99)
val song19 = Song("Witness", "Katy Perry", 2.42, 48)
val song20 = Song("Ur So Gay", "Katy Perry", 1.53, 59)
//val songList = mutableListOf<Song>(song1, song2, song3, song4, song5, song6, song7, song8, song9, song10, song11, song12, song13, song14, song15, song16, song17, song18, song19, song20)
verwaltung.songliste.add(song1)
verwaltung.songliste.add(song2)
verwaltung.songliste.add(song3)
verwaltung.songliste.add(song4)
verwaltung.songliste.add(song5)
verwaltung.songliste.add(song6)
verwaltung.songliste.add(song7)
verwaltung.songliste.add(song8)
verwaltung.songliste.add(song9)
verwaltung.songliste.add(song10)
verwaltung.songliste.add(song11)
verwaltung.songliste.add(song12)
verwaltung.songliste.add(song13)
verwaltung.songliste.add(song14)
verwaltung.songliste.add(song15)
verwaltung.songliste.add(song16)
verwaltung.songliste.add(song17)
verwaltung.songliste.add(song18)
verwaltung.songliste.add(song19)
verwaltung.songliste.add(song20)
val newPlaylist = Playlist(mutableListOf<Song>(song1, song2, song3))
val zufallPlaylist: Playlist = verwaltung.zufallPlaylist()
song5.abspielen()
newPlaylist.alleAbspielen()
println("Spieldauer von newPlaylist: ${newPlaylist.gesamteSpieldauer()}")
println("-----SEPERATOR-----")
zufallPlaylist.alleAbspielen()
println("Spieldauer von zufallPlaylist: ${zufallPlaylist.gesamteSpieldauer()}")
val besterSong: Song = verwaltung.besterSong()
println("Der beste Song in der Datenbank ist: ${besterSong.titel}, ${besterSong.interpret}, ${besterSong.spieldauer}, ${besterSong.spieldauer}")
do{
println("Bitte geben Sie einen Suchbegriff ein!")
val eingabe = readLine().toString()
if(eingabe != "stopp") {
val seekSong = verwaltung.suchen(eingabe)
seekSong.abspielen()
}
}
while(eingabe != "stopp")
}
class Song(val titel: String, val interpret: String, val spieldauer: Double, _bewertung: Int) {
var bewertung = _bewertung
set(value) {
if (value < 0)
field = 0
else if (value > 100)
field = 100
else
field = value
}
fun abspielen() {
var decke: Double
if (spieldauer % 1 == 0.toDouble())
decke = spieldauer
else
decke = spieldauer + 1
val deckeFin = decke.toInt()
for (i in 1..deckeFin)
println("Spiele: $titel von $interpret (Bewertung: $bewertung Punkte)")
}
fun change(newValue: Int) {
if (newValue < 0)
bewertung = 0
else if (newValue > 100)
bewertung = 100
else
bewertung = newValue
}
fun search(searchString: String): Boolean {
var istDrin = false
if (titel.contains(searchString))
istDrin = true
if (interpret.contains(searchString))
istDrin = true
return istDrin
}
}
class Musikverwaltung() {
val songliste: MutableList<Song> = mutableListOf<Song>()
fun hinzufuegen(song: Song) {
songliste.add(song)
}
fun suchen(begriff: String): Song{
for(s in songliste){
if(s.titel.contains(begriff) || s.interpret.contains(begriff)) {
return s
}
}
return songliste.get(0)
}
fun besterSong(): Song{
var tmp = songliste.get(0)
for(s in songliste){
if(s.bewertung > tmp.bewertung)
tmp = s
}
return tmp
}
fun zufallPlaylist(): Playlist{
val zufallGen = Random()
val newSongliste: MutableList<Song> = mutableListOf<Song>()
var laengePlaylist = zufallGen.nextInt(songliste.size)
var istVorhanden = false
for(i in 0..laengePlaylist){
for (s in newSongliste){
if(songliste.get(zufallGen.nextInt(songliste.size)) == s)
istVorhanden = true
}
if(!istVorhanden)
newSongliste.add(songliste.get(zufallGen.nextInt(songliste.size)))
else
laengePlaylist++
}
return Playlist(newSongliste)
}
}
class Playlist(val songliste: MutableList<Song>) {
fun gesamteSpieldauer(): Double {
var temp = 0.toDouble()
for (s in songliste) {
temp += s.spieldauer
}
return temp
}
fun alleAbspielen() {
for (s in songliste) {
s.abspielen()
}
}
}
Comments
0 B
|👍
/👎
0 B
|👍
/👎