I am having problems with this part of the code in which I have to delete an Arraylist line by entering a song using the keyboard and then search the Arraylist and if it finds said song then it deletes it. I'll pass you the main and the Playlist class so that you can take a look at it and you can help me to solve it, since personally I have been trying it by myself but there is no way to get it out
Playlist class
import java.util.ArrayList;
import java.util.Scanner;
public class Playlist {
Scanner sc = new Scanner(System.in);
private String nombrecancion;
private String Artist;
private String Genre;
private int Year;
/**
* @param songName
* @param artist
* @param genre
* @param year
*/
private static ArrayList<Playlist> songs = new ArrayList<>();
public Playlist(String nombrecancion, String Artist, String genre, int year) {
this.nombrecancion = nombrecancion;
this.Artist = Artist;
this.Genre = genre;
this.Year = year;
}
public Playlist(){
}
public static void addSong(String SongName, String Artist, String Genre, int Year) {
songs.add(new Playlist(SongName, Artist, Genre, Year));
}
public void deleteSong(String SongName, String Artist, String Genre, int Year){
String cancion;
System.out.println("Entra canción");
cancion=sc.nextLine();
boolean busqueda=songs.contains(cancion);
songs.remove(SongName);
}
public static void listSong() {
for (int i=0;i<songs.size();i++){
System.out.println(songs.get(i));
}
}
@Override
public String toString() {
return "Nombre de la cancion : " + nombrecancion + " Artista : " + Artist + " Género: " + Genre + " Año :"
+ Year + "";
}
public String getArtist() {
return Artist;
}
public static void listmenu(){
System.out.println("1.Add a new song to Playlist");
System.out.println("2.Delete song from Playlist");
System.out.println("3.List songs by artist");
System.out.println("4.List top 5 songs with a specific hastag");
System.out.println("5.Exit");
}
}
Main
import java.util.InputMismatchException; import java.util.Scanner;
public class Main { public static void main(String[] args) {
boolean salida = false;
int option;
Scanner sc = new Scanner(System.in);
Playlist playlist=new Playlist();
String nombrecancion = null;
String Artista = null;
String Genero = null;
int popular = 0;
int Any = 0;
String hastags = null;
do {
Playlist.listmenu();
try {
System.out.print("Please choose an option:");
option = sc.nextInt();
switch (option) {
case 1:
System.out.print("SongName?:");
sc.nextLine();
nombrecancion = sc.nextLine();
System.out.print("Artist?:");
Artista = sc.nextLine();
System.out.print("Genre?:");
Genero = sc.nextLine();
System.out.print("Year?:");
Any = sc.nextInt();
Playlist.addSong(nombrecancion, Artista, Genero, Any);
System.out.println("How popular is this?[1-10]");
popular = sc.nextInt();
System.out.println("Add some hastags to the song: #w,#y : ");
sc.nextLine();
hastags = sc.nextLine();
System.out.println("You range is " + " " + popular + " And your hastags is " + " " + hastags);
break;
case 2:
System.out.println("You choose delete song");
playlist.deleteSong();
break;
case 3:
System.out.println("You choose List songs by artist");
String Artistas;
System.out.println("Enter an Artist");
Artistas=sc.nextLine();
Playlist.listSong();
break;
case 4:
System.out.println("You choose List top 5 songs with a specific hastag");
break;
case 5:
salida = true;
System.out.println("May the Music be with you");
break;
default:
System.out.println("Only numbers from 1 to 5");
}
} catch (InputMismatchException e) {
System.out.println("You need to enter an input");
sc.next(); // Evitamos que entre en bucle
}
} while (!salida);
}}