Verarbeitungs-Methoden zur Playlist-Analyse hinzugefuegt

main
Giorgi Vardanashvili 2026-11-15 20:48:08 +01:00
parent c5ee072b4e
commit 0872bdf3c3
1 changed files with 58 additions and 1 deletions

View File

@ -4,9 +4,19 @@ import java.util.Scanner;
public class PlaylistAnalyse {
public static void main(String[] args) throws Exception {
String dateipfad = "playlist.csv";
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();
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;
}
}