Taller de Programación Orientada a Objetos
Semana 9
Semana 9
Incorporación de patrones de diseño en la implementación del proyecto.
public class Menu { public Menu() { BufferedReader entrada = null; try { System.out.println("Seleccione una opcion:"); Nuevo n = new Nuevo(); Registro r = new Registro(); System.out.println("Selecciona el registro que quieres graficar:"); BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); String linea = in.readLine(); int x = Integer.parseInt(linea); if (x == 1) { System.out.println("Seleccionado registro 1\n"); Grafica gra = new Grafica(); System.out.println("Deseas guardar la grafica: Si/No\n"); } } catch (Exception e) { System.err.println("Error"); System.exit(-1); } finally { if (entrada != null) { try { entrada.close(); } catch (Exception ex) {} } } } public static void main(String[] args) { System.out.println("Esta es la ventana del Menu\n"); Menu m = new Menu(); System.out.println("Cerrar programa\n"); return; } }Es la clase Menu, donde la función main crea el mismo Menu, y este es el que nos permitirá ver las opciones disponibles en la ventana principal del programa.
public Nuevo() { try { FileWriter fw = new FileWriter("proyecto/nuevo.txt"); BufferedWriter bw = new BufferedWriter(fw); PrintWriter salida = new PrintWriter(bw); salida.println("Esteban"); salida.println("Cecilia"); salida.println("Roberto"); salida.println("Juan"); salida.close(); System.out.println("Se creo un nuevo archivo\n"); } catch(java.io.IOException ioex) { System.out.println("Se presento el error: " + ioex.toString()); } } public void agregarColumna() { } public void visualizar() { }En esta clase Nuevo para un nuevo registro he hecho que el programa cree una lista de nombres simple pero desde el mismo programa, pero esa no es la idea, ya que el usuario es el que ira agregando esa información.
public Registro() { System.out.println("Entra a Registro"); System.out.println("Ver registros...\n"); File archivo = null; FileReader fr = null; BufferedReader br = null; try { System.out.println("1. Registro de nombres"); archivo = new File("proyecto/nuevo.txt"); fr = new FileReader(archivo); br = new BufferedReader(fr); String linea; while((linea = br.readLine()) != null) System.out.println(linea); } catch(Exception e) { e.printStackTrace(); } }Nos lee los datos que están contenidos en el archivo creado por Nuevo, y es aquí donde se comprobará que bases de datos se tienen disponibles, y poder mostrarlas al usuario.
/** * Class Grafica */ public class Grafica extends Menu { // // Fields // // // Constructors // public Grafica () { }; // // Methods // // // Accessor methods // // // Other methods // /** */ public void obtenerDatos( ) { } /** */ public void solicitarGrafica( ) { } /** */ public void guardar( ) { } }
/** * Class Histograma */ public class Histograma extends Grafica { // // Fields // private String xlabel; private String ylabel; private float rangox; // // Constructors // public Histograma () { }; // // Methods // // // Accessor methods // /** * Set the value of xlabel * @param newVar the new value of xlabel */ private void setXlabel ( String newVar ) { xlabel = newVar; } /** * Get the value of xlabel * @return the value of xlabel */ private String getXlabel ( ) { return xlabel; } /** * Set the value of ylabel * @param newVar the new value of ylabel */ private void setYlabel ( String newVar ) { ylabel = newVar; } /** * Get the value of ylabel * @return the value of ylabel */ private String getYlabel ( ) { return ylabel; } /** * Set the value of rangox * @param newVar the new value of rangox */ private void setRangox ( float newVar ) { rangox = newVar; } /** * Get the value of rangox * @return the value of rangox */ private float getRangox ( ) { return rangox; } // // Other methods // /** */ public void editar( ) { } /** */ public void visualizar( ) { } }
/** * Class Nuevo */ public class Nuevo extends Registro { // // Fields // // // Constructors // public Nuevo () { }; // // Methods // // // Accessor methods // // // Other methods // /** */ public void agregarColumna( ) { } /** */ public void agregarFila( ) { } /** */ public void verContenido( ) { } }