package prueba; import [Link].*; import [Link]; public class CEjemplo057 { static Scanner Leer = new Scanner(System.
in); public static void main(String[] args) throws IOException { int resp; do { resp = mostrarOpciones(); switch (resp) { case 1: ingresarRegistro(); break; case 2: modificarRegistro(); break; case 3: eliminarRegistro(); break; case 4: listarRegistros(); break; } } while (resp < 5); } public static int mostrarOpciones() { [Link]("[1] Ingresar nuevo registro"); [Link]("[2] Modificar un registro"); [Link]("[3] Eliminar un registro"); [Link]("[4]Listar todos los registros"); [Link]("[5] Salir"); [Link]("\tEscriba numero de opcion: "); return [Link](); } public static void ingresarRegistro() throws IOException { RandomAccessFile archivo; File fichero = new File("..//[Link]"); if ([Link]() && ![Link]()) { throw new IOException([Link]() + " no es un fichero"); archivo = new RandomAccessFile(fichero, "rw"); // declarar los datos a escribir String id, nombre; int nota1, nota2; int tamReg = 140; String resp = "s"; int i = (int) [Link]((double) [Link]() / 140.0); [Link]("\n"); do { [Link]("IdAlumno :"); id = [Link](); [Link]("Nombre :"); nombre = [Link](); [Link]("Nota 1 :"); nota1 = [Link](); [Link]("Nota 2 :"); nota2 = [Link](); [Link](i * tamReg); // almacenar los datos en el fichero [Link](id); [Link](nombre); [Link](nota1); [Link](nota2); [Link]("\n\tDesea continuar s/n: "); resp = [Link]();
[Link]("\n"); i++; } while ([Link]("s")); } public static void modificarRegistro() throws IOException { RandomAccessFile archivo; File fichero = new File("..//[Link]"); if ([Link]() && ![Link]()) { throw new IOException([Link]() + " no es un fichero"); } archivo = new RandomAccessFile(fichero, "rw"); // declarar los datos a escribir String id, nombre; int nota1, nota2; String resp = "s"; int i = (int) [Link]((double) [Link]() / 140.0); int nReg; int op = 0; do { do { [Link]("[1] Cambiar IdAlumno"); [Link]("[2] Cambiar Nombre "); [Link]("[3] Cambiar Nota 1 "); [Link]("[4] Cambiar Nota 2 "); [Link]("[5] Salir "); [Link]("\tEscriba numero de opcion: "); op = [Link](); [Link]("\n"); if (op == 5) { return; } [Link]("Ingrese el numero de registro que desea modificar:"); nReg = [Link](); [Link]("\n"); [Link]((nReg - 1) * 140); // almacenar los datos en el fichero switch (op) { case 1: [Link]("Ingrese nuevo codigo: "); id = [Link](); [Link](id); break; case 2: [Link]("Ingrese nuevo nombre: "); id = [Link](); nombre = [Link](); [Link](nombre); break; case 3: id = [Link](); nombre = [Link](); nota1 = [Link](); [Link](nota1); break; case 4: [Link]("Ingrese nueva nota: "); id = [Link](); nombre = [Link](); nota1 = [Link](); nota2 = [Link](); [Link](nota2); break; }
} while (op < 5); [Link]("\n\tDesea continuar s/n: "); resp = [Link](); [Link]("\n"); } while ([Link]("s")); } public static void eliminarRegistro() throws IOException { try { RandomAccessFile archivo; archivo = new RandomAccessFile ("..//[Link]", "rw"); int nReg; [Link]("Ingrese el numero de registro que desea eliminar: "); nReg = [Link](); [Link]((nReg - 1) * 140); [Link]("*"); [Link](""); [Link](0); [Link](0); } catch (IOException e) { [Link]("\n\nFin del listado"); } } public static void listarRegistros() throws IOException { try { RandomAccessFile archivo; archivo = new RandomAccessFile("..//[Link]", "r"); // declarar los datos a ingresar String id, nombre; char car = '*'; int nota1, nota2; int i = (int) [Link]((double) [Link]() / 140.0); int j = 0; do { [Link](j * 140); //leer id = [Link](); nombre = [Link](); nota1 = [Link](); nota2 = [Link](); // mostrar los datos if ([Link](0) != car) { [Link]("\n" + id + " "+ nombre + " " + nota1 + " " + nota2); } j++; } while (j <= i); } catch (IOException e) { [Link]("\n\nFin del listado"); } }}