Verarbeitungs-Methoden zur Playlist-Analyse hinzugefuegt
parent
c5ee072b4e
commit
0872bdf3c3
|
|
@ -4,9 +4,19 @@ import java.util.Scanner;
|
||||||
public class PlaylistAnalyse {
|
public class PlaylistAnalyse {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
String dateipfad = "playlist.csv";
|
String dateipfad = "playlist.csv";
|
||||||
Song[] songs = ladeSongsAusDatei(dateipfad);
|
Song[] songs = ladeSongsAusDatei(dateipfad);
|
||||||
System.out.println("Erfolgreich geladene Songs: " + songs.length);
|
|
||||||
|
|
||||||
|
int gesamtDauer = berechneGesamtDauer(songs);
|
||||||
|
double durchschnittPop = berechneDurchschnittPopularitaet(songs);
|
||||||
|
Song laengsterSong = findeLaengstenSong(songs);
|
||||||
|
Song beliebtesterSong = findeBeliebtestenSong(songs);
|
||||||
|
int anzahlWeeknd = zaehleSongsVonKuenstler(songs, "The Weeknd");
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("Berechnungen erfolgreich! Gesamtdauer in Sekunden: " + gesamtDauer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -48,4 +58,51 @@ public class PlaylistAnalyse {
|
||||||
sc.close();
|
sc.close();
|
||||||
return songs;
|
return songs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static int berechneGesamtDauer(Song[] songs) {
|
||||||
|
int summe = 0;
|
||||||
|
for (int i = 0; i < songs.length; i++) {
|
||||||
|
summe += songs[i].dauerSekunden;
|
||||||
|
}
|
||||||
|
return summe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double berechneDurchschnittPopularitaet(Song[] songs) {
|
||||||
|
int summe = 0;
|
||||||
|
for (int i = 0; i < songs.length; i++) {
|
||||||
|
summe += songs[i].popularitaet;
|
||||||
|
}
|
||||||
|
return (double) summe / songs.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Song findeLaengstenSong(Song[] songs) {
|
||||||
|
Song bester = songs[0];
|
||||||
|
for (int i = 1; i < songs.length; i++) {
|
||||||
|
if (songs[i].dauerSekunden > bester.dauerSekunden) {
|
||||||
|
bester = songs[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bester;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Song findeBeliebtestenSong(Song[] songs) {
|
||||||
|
Song bester = songs[0];
|
||||||
|
for (int i = 1; i < songs.length; i++) {
|
||||||
|
if (songs[i].popularitaet > bester.popularitaet) {
|
||||||
|
bester = songs[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bester;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int zaehleSongsVonKuenstler(Song[] songs, String gesuchterKuenstler) {
|
||||||
|
int anzahl = 0;
|
||||||
|
for (int i = 0; i < songs.length; i++) {
|
||||||
|
if (songs[i].kuenstler.equalsIgnoreCase(gesuchterKuenstler)) {
|
||||||
|
anzahl++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return anzahl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue