Anda di halaman 1dari 7

INSTITUTO TECNOLOGICO SUPERIOR DE SAN ANDRES TUXTLA AREA ACADEMICA CODIGO: IINF 1003

REVISION: 0

MANUAL DE PRCTICAS DE LA MATERIA: Administracin y Organizacin de Datos


ASIGNATURA: PRCTICA NO. 3

Administracin y Organizacin de Datos


Manejo de Archivos y Organizacin secuencial en Archivos Identificar y Resolver la estructura de acceso secuencial con archivos
FUNDAMENTO TEORICO

OBJETIVO:

MATERIAL/EQUIPO Libreta u hojas blancas de papel bond Lpiz PC Lenguaje de Programacin, IDE Eclipse METODOLOGIA Y DESARROLLO 1. Analice las clases File, StringTokenizer, BufferedReader, PrintWriter de Java y genere una tabla con los mtodos que se emplean en la clase Text.java que se proporciona en los siguientes puntos

2. Crear un archivo de texto (Fichero.txt) utilizando un editor e ingresar los valores 2 3

INSTITUTO TECNOLOGICO SUPERIOR DE SAN ANDRES TUXTLA AREA ACADEMICA

MANUAL DE PRCTICAS DE LA MATERIA: Administracin y Organizacin de Datos

CODIGO: IINF - 1003


REVISION: 0

3. Capture, compile y ejecute el siguiente ejemplo a. Inicie Eclipse en el Menu File / New / Java Project cree el proyecto con el nombre AOD y clic en el botn Finish, se deber obtener como la imagen que aparece a la derecha

b. En la carpeta de proyecto AOD expandir haciendo clic en el smbolo + y dentro


aparecer el directorio SRC, hacer clic botn derecho new / package y en el campo name escribir uni2 y dentro de uni2 clic derecho new / class y colocar el nombre j035 a la clase, hacer clic en el botn finish. (Nota. La clase j035 emplea la clase Text. Esta se proporciona debajo de este bloque)

INSTITUTO TECNOLOGICO SUPERIOR DE SAN ANDRES TUXTLA AREA ACADEMICA

MANUAL DE PRCTICAS DE LA MATERIA: Administracin y Organizacin de Datos

CODIGO: IINF - 1003


REVISION: 0

Clase j035.java
package uni2; import java.io.*; class j035 { public static void main (String [] args) throws IOException int count;

INSTITUTO TECNOLOGICO SUPERIOR DE SAN ANDRES TUXTLA AREA ACADEMICA

MANUAL DE PRCTICAS DE LA MATERIA: Administracin y Organizacin de Datos

CODIGO: IINF - 1003


REVISION: 0

double total = 0; double number; BufferedReader in = Text.open(System.in); BufferedReader fin = Text.open("Fichero.txt"); System.out.println("****** Suma de numeros desde un fichero ******"); Text.prompt ("Cuantos numeros hay?"); count = Text.readInt(in); for (int i = 1; i <= count; i++){ number = Text.readDouble(fin); total += number; } System.out.println("Ya es suficiente, gracias."); System.out.println("El total es "+total); } }

Clase Text.java esta se debe de cargar en el mismo proyecto que la clase j035
package uni2; import java.io.*; import java.util.*; import java.text.*; class Text { public Text () {}; private static StringTokenizer T; private static String S; public static BufferedReader open (InputStream in) { return new BufferedReader(new InputStreamReader(in)); } public static BufferedReader open (String filename) throws FileNotFoundException { return new BufferedReader (new FileReader (filename)); } public static PrintWriter create (String filename) throws IOException { return new PrintWriter (new FileWriter (filename)); } public static void prompt (String s) { System.out.print(s + " "); System.out.flush(); } public static int readInt (BufferedReader in) throws IOException { if (T==null) refresh(in); while (true) { try { return Integer.parseInt(T.nextToken());

INSTITUTO TECNOLOGICO SUPERIOR DE SAN ANDRES TUXTLA AREA ACADEMICA

MANUAL DE PRCTICAS DE LA MATERIA: Administracin y Organizacin de Datos

CODIGO: IINF - 1003


REVISION: 0

} catch (NoSuchElementException e1) { refresh (in); } catch (NumberFormatException e2) { System.out.println("Error in number, try again."); } } } public static char readChar (BufferedReader in) throws IOException { if (T==null) refresh(in); while (true) { try { return T.nextToken().trim().charAt(0); } catch (NoSuchElementException e1) { refresh (in); } } } public static double readDouble (BufferedReader in) throws IOException { if (T==null) refresh(in); while (true) { try { String item = T.nextToken(); return Double.valueOf(item.trim()).doubleValue(); } catch (NoSuchElementException e1) { refresh (in); } catch (NumberFormatException e2) { System.out.println("Error in number, try again."); } } } public static String readString (BufferedReader in) throws IOException { if (T==null) refresh (in); while (true) { try { return T.nextToken(); } catch (NoSuchElementException e1)

INSTITUTO TECNOLOGICO SUPERIOR DE SAN ANDRES TUXTLA AREA ACADEMICA

MANUAL DE PRCTICAS DE LA MATERIA: Administracin y Organizacin de Datos

CODIGO: IINF - 1003


REVISION: 0

{ refresh (in); } } } private static void refresh (BufferedReader in) throws IOException { S = in.readLine (); if (S==null) throw new EOFException(); T = new StringTokenizer (S); } // Metodos Escritura private static DecimalFormat N = new DecimalFormat(); private static final String spaces = "

";

public static String writeDouble (double number, int align, int frac) { N.setGroupingUsed(false); N.setMaximumFractionDigits(frac); N.setMinimumFractionDigits(frac); String num = N.format(number); if (num.length() < align) num = spaces.substring(0,align-num.length()) + num; return num; } public static String writeInt (int number, int align) { N.setGroupingUsed(false); N.setMaximumFractionDigits(0); String num = N.format(number); if (num.length() < align) num = spaces.substring(0,align-num.length()) + num; return num; } }

4. Realice el reporte de la prctica utilizando la seccin de RESULTADOS incluido en el manual de prcticas. La salida deber ser similar a la siguiente imagen

INSTITUTO TECNOLOGICO SUPERIOR DE SAN ANDRES TUXTLA AREA ACADEMICA

MANUAL DE PRCTICAS DE LA MATERIA: Administracin y Organizacin de Datos

CODIGO: IINF - 1003


REVISION: 0

CUESTIONARIO Cul es la salida del fichero j035.java? Qu mtodos de la clase Text permiten abrir el fichero texto y que tipo de dato retorna? Explica la funcionalidad de los mtodos readDouble readInt que se emplean en la clase j035? RESULTADOS

NOTAS Y SUGERENCIAS Compare sus notas con algunos conceptos buscados en la internet, as como su clasificacin BIBLIOGRAFIA

Anda mungkin juga menyukai