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