0

I am trying to delete an object from an arrayList:

/*
 * Borrar un Hotel 
 */
System.out.println("Hoteles en el sistema");
for(Hotel hotelActual : hoteles) {
    System.out.println(hotelActual.getNombreHotel() + "  " + hotelActual.getDireccion() + "  "
            + hotelActual.getNumeroEstrellas() + "  " + hotelActual.getNumeroHabitaciones() + " "
            + hotelActual.isJardin() + " " + hotelActual.isPiscina() + " " + hotelActual.isBar() + " "
            + hotelActual.isInstalacionesDeportivas());
}

Hotel borrarHotel = null;

System.out.println("Escriba el nombre del Hotel a borrar: ");
String nombreBorrar = sc.nextLine();
for (Hotel hotelActual : hoteles) {
    if (nombreBorrar.equals(hotelActual.getNombreHotel())) {
        borrarHotel = hotelActual;
        break;
    }
}
if (borrarHotel != null) {
    /*
     * Borramos este objeto de la lista
     */
    hoteles.remove(borrarHotel);
    System.out.println("\n¡Hotel eliminado!");
}

So in the output I have:

Hoteles en el sistema
Gran Hotel Miami  New York  5  700 true true true true
Glory Hotel  Los Angeles  4  450 true true true false
Deluxe dreams  Paris  3  300 true false true false
Renaissance  Madrid  5  800 true true true true
Escriba el nombre del Hotel a borrar: 
Escribe una de las opciones
-------------------------
1. Añadir Hotel
2. Borrar Hotel
3. Ver Estadísticas
4. Salir

   ¿Opcion? 

So it just skips when asking for hotel name to delete

Stephen C
  • 632,615
  • 86
  • 730
  • 1,096
  • so, how should I implement that in my code? –  Jan 13 '21 at 11:26
  • You need to see what the value of `nombreBorrar` actually is. It is most likely NOT the hotel number. And that is most likely because earlier in the code you are using `Scanner` incorrectly. The duplink describes that problem. – Stephen C Jan 13 '21 at 15:36

0 Answers0