import java.util.Scanner; public class CatalogoDeVino2Eqe { public static void…
- User
import java.util.Scanner; public class CatalogoDeVino2Eqe { public static void main(String args[]) { Scanner leer = new Scanner(System.in);
final int TAM_ARREGLO = 100; int opc, cont = 100, celda = 0, dato = 0, resp = 0, nuevaClave, claveD = 0, claveConsulta = 0, claveModificacion = 0; boolean claveDuplicada = false, existeR = false, espacioD = false, claveExistente = false,claveRan = false; int clave[] = new int[TAM_ARREGLO]; String nombres[] = new String[TAM_ARREGLO]; float precio[] = new float[TAM_ARREGLO]; char estante[] = new char[TAM_ARREGLO]; // Menú do { System.out.println("CATALOGO DE VINOS \n"); System.out.println("[1] Registrar Vino:"); System.out.println("[2] Consultar Vino:"); System.out.println("[3] Consultar todos los Vinos:"); System.out.println("[4] Modificar vino:"); System.out.println("[5] Eliminar vino:"); System.out.println("[6] Finalizar programa:"); opc = leer.nextInt(); switch (opc) { case 1: // Altas cont = altasVinos(cont, TAM_ARREGLO, estante, claveD, clave, precio, nombres, espacioD,claveExistente,claveRan); break; case 2: // Consultar por Clave consultaVino(cont, estante, clave, precio, nombres, celda, claveConsulta, existeR); break; case 3: // Consultar todos los Vinos consultaVinos(cont, estante, clave, precio, nombres, existeR); break; case 4: // Modificar vino cont = modificarVino(claveModificacion, celda, cont, estante, clave, precio, nombres, dato, existeR); break; case 5://Eliminar vino cont = eliminarVinos(celda, cont, estante, clave, precio, nombres, dato, resp, claveConsulta, existeR); break; case 6: // Finalizar programa System.out.println("Programa finalizado."); break; default: System.out.println("Opcion no valida. Intentelo de nuevo."); } } while (opc != 6);}
static int altasVinos(int cont, int TAM_ARREGLO, char estante[], int claveD, int clave[], float precio[], String nombres[], boolean espacioD,boolean claveExistente,boolean claveRan) { Scanner leer = new Scanner(System.in);
espacioD = espacioArregloD(cont, espacioD, TAM_ARREGLO); if(espacioD){ System.out.println("La base vinos esta llena"); }else{ System.out.print("Ingrese la clave a registrar: \n"); System.out.print("Clave: \n"); claveD = leer.nextInt(); claveRan = checarRango(espacioD,claveD,claveExistente,clave,cont,claveRan); claveExistente = claveRep(espacioD, claveD, claveExistente, clave,cont); if (claveExistente) { System.out.println("La clave ya existe. Ingrese una nueva.\n"); } else { if (!claveRan){ System.out.println("La clave debe estar entre [1-111]. Ingrese una nueva.\n"); }else { clave[cont] = claveD; leer.nextLine(); // Limpia el enter de la entrada System.out.print("Nombre: \n"); nombres[cont] = leer.nextLine(); System.out.print("Precio: \n"); precio[cont] = leer.nextFloat(); System.out.print("Estante: \n"); estante[cont] = leer.next().charAt(0); leer.nextLine(); // Limpia el enter de la entrada System.out.println("Registro Exitoso"); leer.nextLine(); // Espera un enter cont++; } } } return cont; - Assistant
The issue is with the
espacioArregloDmethod. It is checking ifcontis less thanTAM_ARREGLO(which is 100), but it should be checking ifcontis equal toTAM_ARREGLO.Modify the
espacioArregloDmethod as follows:static boolean espacioArregloD(int cont, boolean espacioD, int TAM_ARREGLO) { if (cont == TAM_ARREGLO) { espacioD = true; } return espacioD; }This way, the method will return
trueonly ifcontis equal toTAM_ARREGLO, indicating that the array is full. - User
No i want it to give me true only when cont is more or equal to 100
- Assistant
Apologies for the confusion. If you want to return
trueonly whencontis more or equal to 100, you can modify theespacioArregloDmethod as follows:static boolean espacioArregloD(int cont, boolean espacioD, int TAM_ARREGLO) { if (cont >= TAM_ARREGLO) { espacioD = true; } return espacioD; }This way, the method will return
trueonly whencontis greater than or equal toTAM_ARREGLO, indicating that the array is full. - User
but why doesnt it work if i have that way, also sorry i only want it to be true if its less than tam arreglo
- Assistant
I apologize for the confusion. If you want the method
espacioArregloDto returntrueonly whencontis less thanTAM_ARREGLO, you can update the method as follows:static boolean espacioArregloD(int cont, boolean espacioD, int TAM_ARREGLO) { if (cont < TAM_ARREGLO) { espacioD = true; } return espacioD; }This way, the method will return
trueonly whencontis less thanTAM_ARREGLO, indicating that there is space available in the array. - User
But that is what i have
- Assistant
If the
espacioArregloDmethod is already implemented as shown above:static boolean espacioArregloD(int cont, boolean espacioD, int TAM_ARREGLO) { if (cont < TAM_ARREGLO) { espacioD = true; } return espacioD; }Then the issue may lie elsewhere in your code. One possibility is that the
TAM_ARREGLOvariable is not set to the correct value. Please double-check that you have correctly definedTAM_ARREGLOand that it is indeed set to 100.If you continue to experience difficulties, please provide more details or share the complete code so that we can help you further.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.