import tools.*;

class Buscar extends Program {
  void run() {
    // Creación de arreglos
    Array tabNombres= new Array(1000);
    Array tabNotas= new Array(1000);
    // Inicialización de los arreglos y cálculo
    // de la mejor nota
    TextReader lect= new TextReader("notas.txt");
    int i= 0;
    double maxNota= 0.0;
    while (true) {
      String lin= lect.readLine();
      if (lect.eofReached()) // Patrón de lectura de datos
        break;
      String nom= trim(substring(lin, 0, 20));
      double nota= parseDouble(trim(substring(lin, 20, 3)));
      // Patrón de inicialización de arreglos
      tabNombres.put(i, nom);
      tabNotas.put(i, nota);
      if (nota>maxNota)
        maxNota= nota;
      i= i+1; // Patrón de conteo para el nro. de línea
    }
    lect.close();
    int nalum= i;
    while (true) {
      print("nombre ? ");
      String nombre= lower(trim(readLine()));
      if (compare(nombre, "fin")==0) {
        break;
      }
      int j=0;
      while (j<nalum && compare(lower(tabNombres.getString(j)), nombre)!=0) {
        j= j+1;
      }
      if (j<nalum) {
        println("Su nota es "+tabNotas.getDouble(j));
      }
      else {
        println("No se encontro este alumno");
      }
    }
    println("Fin.");
  }
}
