Spotify Projekt erstellt
commit
9a8c2fdf7d
|
|
@ -0,0 +1,30 @@
|
||||||
|
/**
|
||||||
|
* stores information about a song
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class Song {
|
||||||
|
private String künstler;
|
||||||
|
private String titel;
|
||||||
|
private int dauer;
|
||||||
|
|
||||||
|
//create a new song
|
||||||
|
public Song(String künstler, String titel, int dauer) {
|
||||||
|
this.künstler = künstler;
|
||||||
|
this.titel = titel;
|
||||||
|
this.dauer = dauer;
|
||||||
|
}
|
||||||
|
//return the artist
|
||||||
|
public String getKünstler() {
|
||||||
|
return künstler;
|
||||||
|
}
|
||||||
|
//return the title
|
||||||
|
public String getTitel() {
|
||||||
|
return titel;
|
||||||
|
}
|
||||||
|
//return the duration
|
||||||
|
public int getDauer() {
|
||||||
|
return dauer;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads songs from CSV file.
|
||||||
|
* Displays songs, total duration and artist search.
|
||||||
|
*/
|
||||||
|
public class SpotifyAnalyse {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
Scanner scanner = new Scanner(new File("spotify.csv"), "UTF-8");
|
||||||
|
|
||||||
|
Song[] songs = new Song[10];
|
||||||
|
int anzahlSongs = 0;
|
||||||
|
//read songs from CSV file
|
||||||
|
while(scanner.hasNextLine()) {
|
||||||
|
String zeile = scanner.nextLine();
|
||||||
|
String[] daten = zeile.split(",");
|
||||||
|
|
||||||
|
if(daten.length == 3 && !daten[0].equals("Künstler")) {
|
||||||
|
String künstler = daten[0];
|
||||||
|
String titel = daten[1];
|
||||||
|
int dauer = Integer.parseInt(daten[2]);
|
||||||
|
|
||||||
|
Song song = new Song(künstler, titel, dauer);
|
||||||
|
songs[anzahlSongs] = song;
|
||||||
|
anzahlSongs++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scanner.close();
|
||||||
|
zeigeSongs(songs, anzahlSongs);
|
||||||
|
|
||||||
|
System.out.println("Anzahl der Songs: " + anzahlSongs);
|
||||||
|
System.out.println("Gesamtdauer: " + gesamtDauer(songs, anzahlSongs) + " Sekunden ");
|
||||||
|
|
||||||
|
sucheSongs(songs, anzahlSongs);
|
||||||
|
}
|
||||||
|
//display all songs
|
||||||
|
public static void zeigeSongs(Song[] songs, int anzahlSongs) {
|
||||||
|
System.out.println("Meine Spotify Playlist: ");
|
||||||
|
|
||||||
|
for(int i = 0; i < anzahlSongs; i++) {
|
||||||
|
System.out.println(songs[i].getKünstler() + "-" + songs[i].getTitel());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//calculate total duration
|
||||||
|
public static int gesamtDauer(Song[] songs, int anzahlSongs) {
|
||||||
|
int gesamt = 0;
|
||||||
|
for ( int i = 0; i < anzahlSongs; i++) {
|
||||||
|
gesamt = gesamt + songs[i].getDauer();
|
||||||
|
}
|
||||||
|
return gesamt;
|
||||||
|
}
|
||||||
|
//search songs by artist
|
||||||
|
public static void sucheSongs(Song[] songs, int anzahlSongs) {
|
||||||
|
Scanner eingabe = new Scanner(System.in);
|
||||||
|
|
||||||
|
System.out.println("Welchen Künstler suchst du?");
|
||||||
|
String gesucht = eingabe.nextLine();
|
||||||
|
|
||||||
|
int gefunden = 0;
|
||||||
|
|
||||||
|
for(int i = 0; i < anzahlSongs; i++) {
|
||||||
|
if(songs[i].getKünstler().equalsIgnoreCase(gesucht)) {
|
||||||
|
System.out.println(songs[i].getKünstler() + " - " + songs[i].getTitel());
|
||||||
|
gefunden++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(gefunden == 0) {
|
||||||
|
System.out.println("Kein Künstler gefunden.");
|
||||||
|
} else {
|
||||||
|
System.out.println("Gefundene Songs: " + gefunden);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
Künstler, Titel, Dauer
|
||||||
|
The Weeknd, Blinding Lights,200
|
||||||
|
Drake,One Dance,173
|
||||||
|
The Weeknd,Starboy,230
|
||||||
|
Billie Eilish,Bad Guy,194
|
||||||
|
Drake,Gods Plan,198
|
||||||
|
Dua Lipa,Levitating,203
|
||||||
|
Ariana Grande,7 Rings,179
|
||||||
|
The Weeknd,Save Your Tears,215
|
||||||
|
Billie Eilish,Ocean Eyes,200
|
||||||
|
Dua Lipa,New Rules,209
|
||||||
|
Loading…
Reference in New Issue