From aa28997de299c5ca7ceaa9e985d02c2ac7dad4d3 Mon Sep 17 00:00:00 2001 From: PascoDominguez Date: Sat, 26 Aug 2017 10:41:37 -0600 Subject: [PATCH 1/5] Ejercicios para 26/8/2017 --- EF1.java | 29 ++++++++++++++++------------ EF2.java | 58 +++++++++++++++++++++++++++++++++++++++++++++++-------- README.md | 55 ---------------------------------------------------- 3 files changed, 67 insertions(+), 75 deletions(-) delete mode 100644 README.md diff --git a/EF1.java b/EF1.java index 66ebb69..d08c8f1 100644 --- a/EF1.java +++ b/EF1.java @@ -1,15 +1,20 @@ -public class EF1{ - - public static void main(String args[]){ - int n = Integer.parseInt(args[0]); - System.out.println(Factorial(n)); - } +public class EF1 { - public static int Factorial(int n){ - if(){//Escribir condición de salida - return 1; - }else{//Escribir el retorno para la recursividad + public static void main(String args[]) { + int n = Integer.parseInt(args[0]); + EF1 ef = new EF1(); + System.out.println(ef.factorial(n)); + } - } - } + + + public static int factorial(int fac) { + + if (fac == 0) { + return 1; + } else { + return fac * (factorial(fac - 1)); + } + + } } \ No newline at end of file diff --git a/EF2.java b/EF2.java index c70e201..2a342ae 100644 --- a/EF2.java +++ b/EF2.java @@ -1,9 +1,51 @@ -public class EF2{ - - public static void main(String args[]){ - - - } - - +public class EF2 { + + public static void main(String args[]) { + + int array[] = {2, 3, 8, 109, 13, 4, 18, 10, 23, 18, 50, 11, 13, 2}; + System.out.println("------- ENTRADA -------"); + for (int i = 0; i < array.length; i++) { + if (i == 0) { + System.out.print("{ "); + } + if (i > 0) { + System.out.print(", "); + } + System.out.print(" "+array[i]); + } + System.out.println(" }"); + + + EF2 bs = new EF2(); + System.out.println("------- SALIDA -------"); + bs.sort(array); + bs.print(array); + } + + public void sort(int array[]) { + + for (int i = 0; i < array.length; i++) { + for (int j = 1; j < array.length - i; j++) { + if (array[j - 1] > array[j]) { + int temporal = array[j]; + array[j] = array[j - 1]; + array[j - 1] = temporal; + } + } + + } + } + + public void print(int array[]) { + for (int i = 0; i < array.length; i++) { + if (i == 0) { + System.out.print("{ "); + } + if (i > 0) { + System.out.print(", "); + } + System.out.print(" "+array[i]); + } + System.out.println(" }"); + } } \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 6e22ef5..0000000 --- a/README.md +++ /dev/null @@ -1,55 +0,0 @@ -# Tarea Final - -## Descripción -La tarea final consiste en una serie de ejercicios que se dejarán periódicamente, cada ejercicio se relacionan con los temas de laboratorio vistos. Los ejercicios son diseñados para ser entregados en el menor tiempo posible - -## Prerrequisitos - -- Los nombres de cada clase debe de ser EF<#> -- Los únicos archivos que se deben de subir son los .java -- En la descripción del commit debe de llevar la fecha de entrega el ejercicio - -| Ejercicio | Nombre |descripción del commit| -| ------ | ------ | ------ | -| Ejercicio 1 | EF1.java |Ejercicios para 26/8/2017| -| Ejercicio 2 | EF2.java |Ejercicios para 26/8/2017| -| Ejercicio 3 | EF3.java |Ejercicios para 2/9/2017| -| Ejercicio 4 | EF4.java |Ejercicios para 2/9/2017| - - - -Deben de recordar que el nombre del archivo debe de ser el mismo que el nombre de la clase para el ejercicio 1. - -```java -public class EF1{ - código... -} -``` - -## Ejercicio 1 -Deben de realizar por medio un algoritmo recursivo el Factorial de un número dado como entrada por un parámetro del método main. Deben de entregar el sábado 26 de agosto antes de las 15:00 - -```java -public class EF1{ - public static void main(String args[]){ - int n = Integer.parseInt(args[0]); - System.out.println(Factorial(n)); - } -} -``` - - -## Ejercicio 2 - -Deben de realizar el algoritmo de ordenamiento de búrbuja -con el siguiente arreglo, deben de imprimir únicamente de salida el arreglo ordenado separado por comas entre llaves, deben de considerar que el último no lleva coma. Deben de entregar el sábado 26 de agosto antes de las 15:00 - - __Entrada__ -``` -{2, 3, 8, 109, 13, 4, 18, 10, 23, 18, 50, 11, 13, 2} -``` -__Salida__ -``` -{2, 2, 3, 4, 8, 10, 11, 13, 13, 18, 18, 23, 50, 109} -``` - From bcbac8c9cd16f3592d806a5069ccc5b84c3353a0 Mon Sep 17 00:00:00 2001 From: PascoDominguez Date: Sat, 2 Sep 2017 23:22:45 -0600 Subject: [PATCH 2/5] Ejercicios para 2/9/2017 --- EF3.java | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 EF3.java diff --git a/EF3.java b/EF3.java new file mode 100644 index 0000000..d099889 --- /dev/null +++ b/EF3.java @@ -0,0 +1,66 @@ +import java.util.Scanner; +public class EF3 { + + public static void main(String args[]) { + Encriptador p = new Encriptador(); + System.out.println("Escria su mensaje"); + Scanner sc = new Scanner(System.in); + String mensaje = sc.nextLine(); + p.cifrar(mensaje); + } + + public static class Encriptador { + + private String abc[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", + "n", "ñ", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",}; + + private String mensaje; + + private String[] cifrado; + private int cadenaNumeros[]; + + public String cifrar(String mensaje) { + + System.out.println("+++++++++++ MENSAJE A CIFRAR +++++++++"); + System.out.println(mensaje); + System.out.println(""); + System.out.println(""); + String cadena = ""; + //limpia espacios en blanco + for (int i = 0; i < mensaje.length(); i++) { + if (mensaje.charAt(i) != ' ') { + cadena = cadena + mensaje.charAt(i); + } + } + //compara cada caracter + cadenaNumeros = new int[cadena.length()]; + for (int c = 0; c < cadena.length(); c++) { + for (int x = 0; x < abc.length; x++) { + if (cadena.charAt(c) == abc[x].charAt(0)) { + cadenaNumeros[c] = (5 * x + 11) % 26 + 1; + + } + } + } + + //cifrado + String cifradoMostrar = ""; + cifrado = new String[cadenaNumeros.length]; + System.out.println("+++++++++++ MENSAJE CIFRADO +++++++++"); + for (int i = 0; i < cadena.length(); i++) { + for (int j = 0; j < abc.length; j++) { + if (cadenaNumeros[i] == j) { + cifrado[i] = abc[j]; + System.out.print(abc[j]); + cifradoMostrar = abc[j]; + } + } + } + System.out.println(""); + System.out.println(""); + + return cifradoMostrar; + } + + } +} \ No newline at end of file From e0159e921b3ed144a70d0e2dcd5ecddc0b3f27d5 Mon Sep 17 00:00:00 2001 From: PascoDominguez Date: Sat, 2 Sep 2017 23:34:53 -0600 Subject: [PATCH 3/5] Ejercicio para 2/9/2017 --- EF1.java | 20 -------------------- EF2.java | 51 --------------------------------------------------- 2 files changed, 71 deletions(-) delete mode 100644 EF1.java delete mode 100644 EF2.java diff --git a/EF1.java b/EF1.java deleted file mode 100644 index d08c8f1..0000000 --- a/EF1.java +++ /dev/null @@ -1,20 +0,0 @@ -public class EF1 { - - public static void main(String args[]) { - int n = Integer.parseInt(args[0]); - EF1 ef = new EF1(); - System.out.println(ef.factorial(n)); - } - - - - public static int factorial(int fac) { - - if (fac == 0) { - return 1; - } else { - return fac * (factorial(fac - 1)); - } - - } -} \ No newline at end of file diff --git a/EF2.java b/EF2.java deleted file mode 100644 index 2a342ae..0000000 --- a/EF2.java +++ /dev/null @@ -1,51 +0,0 @@ -public class EF2 { - - public static void main(String args[]) { - - int array[] = {2, 3, 8, 109, 13, 4, 18, 10, 23, 18, 50, 11, 13, 2}; - System.out.println("------- ENTRADA -------"); - for (int i = 0; i < array.length; i++) { - if (i == 0) { - System.out.print("{ "); - } - if (i > 0) { - System.out.print(", "); - } - System.out.print(" "+array[i]); - } - System.out.println(" }"); - - - EF2 bs = new EF2(); - System.out.println("------- SALIDA -------"); - bs.sort(array); - bs.print(array); - } - - public void sort(int array[]) { - - for (int i = 0; i < array.length; i++) { - for (int j = 1; j < array.length - i; j++) { - if (array[j - 1] > array[j]) { - int temporal = array[j]; - array[j] = array[j - 1]; - array[j - 1] = temporal; - } - } - - } - } - - public void print(int array[]) { - for (int i = 0; i < array.length; i++) { - if (i == 0) { - System.out.print("{ "); - } - if (i > 0) { - System.out.print(", "); - } - System.out.print(" "+array[i]); - } - System.out.println(" }"); - } -} \ No newline at end of file From 3472a5bb75967271ba2f31dbeacd5f716378ef31 Mon Sep 17 00:00:00 2001 From: PascoDominguez Date: Sat, 9 Sep 2017 22:09:06 -0600 Subject: [PATCH 4/5] Ejercicios para 9/09/2017 --- EF3.java | 66 ---------------------------------------- EF4.java | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 66 deletions(-) delete mode 100644 EF3.java create mode 100644 EF4.java diff --git a/EF3.java b/EF3.java deleted file mode 100644 index d099889..0000000 --- a/EF3.java +++ /dev/null @@ -1,66 +0,0 @@ -import java.util.Scanner; -public class EF3 { - - public static void main(String args[]) { - Encriptador p = new Encriptador(); - System.out.println("Escria su mensaje"); - Scanner sc = new Scanner(System.in); - String mensaje = sc.nextLine(); - p.cifrar(mensaje); - } - - public static class Encriptador { - - private String abc[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", - "n", "ñ", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",}; - - private String mensaje; - - private String[] cifrado; - private int cadenaNumeros[]; - - public String cifrar(String mensaje) { - - System.out.println("+++++++++++ MENSAJE A CIFRAR +++++++++"); - System.out.println(mensaje); - System.out.println(""); - System.out.println(""); - String cadena = ""; - //limpia espacios en blanco - for (int i = 0; i < mensaje.length(); i++) { - if (mensaje.charAt(i) != ' ') { - cadena = cadena + mensaje.charAt(i); - } - } - //compara cada caracter - cadenaNumeros = new int[cadena.length()]; - for (int c = 0; c < cadena.length(); c++) { - for (int x = 0; x < abc.length; x++) { - if (cadena.charAt(c) == abc[x].charAt(0)) { - cadenaNumeros[c] = (5 * x + 11) % 26 + 1; - - } - } - } - - //cifrado - String cifradoMostrar = ""; - cifrado = new String[cadenaNumeros.length]; - System.out.println("+++++++++++ MENSAJE CIFRADO +++++++++"); - for (int i = 0; i < cadena.length(); i++) { - for (int j = 0; j < abc.length; j++) { - if (cadenaNumeros[i] == j) { - cifrado[i] = abc[j]; - System.out.print(abc[j]); - cifradoMostrar = abc[j]; - } - } - } - System.out.println(""); - System.out.println(""); - - return cifradoMostrar; - } - - } -} \ No newline at end of file diff --git a/EF4.java b/EF4.java new file mode 100644 index 0000000..620d652 --- /dev/null +++ b/EF4.java @@ -0,0 +1,91 @@ +package tareafinal; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.WindowConstants; + +public class EF4 extends JFrame { + + private JPanel contentPane; + private JButton btnOk; + private JTextField txtIngrese, txtResultado; + private JLabel lblIngrese, lblResultado; + + public static void main(String args[]) { + EF4 ventana = new EF4(); + ventana.show(); + } + + public EF4() { + setSize(250, 300); + setTitle("Sumadora"); + setLocationRelativeTo(null); + setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + setLocationRelativeTo(null); + setResizable(false); + setVisible(true); + this.iniciar_componente(); + + } + + public void iniciar_componente() { + this.contentPane = (JPanel) getContentPane(); + this.contentPane.setLayout(null); + this.contentPane.setSize(250, 300); + + this.lblIngrese = new JLabel("Ingrese los numeros"); + this.lblIngrese.setSize(150, 30); + this.lblIngrese.setLocation(60, 20); + this.contentPane.add(this.lblIngrese); + + this.txtIngrese = new JTextField(); + this.txtIngrese.setSize(150, 30); + this.txtIngrese.setLocation(10, 60); + this.contentPane.add(this.txtIngrese); + + this.btnOk = new JButton("OK"); + this.btnOk.setSize(60, 30); + this.btnOk.setLocation(170, 60); + this.contentPane.add(this.btnOk); + + this.lblResultado = new JLabel("resultado"); + this.lblResultado.setSize(150, 30); + this.lblResultado.setLocation(60, 120); + this.contentPane.add(this.lblResultado); + + this.txtResultado = new JTextField(); + this.txtResultado.setSize(80, 30); + this.txtResultado.setLocation(45, 150); + this.btnOk.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent evt) { + btnOK(evt); + } + }); + this.contentPane.add(this.txtResultado); + } + + public String getSuma(String entrada) { + String[] numeros = entrada.split(", "); + int suma = 0; + //Realizar suma + for(String numero:numeros) + { + suma += Integer.parseInt(numero); + } + return suma+""; + } + + public void btnOK(ActionEvent evt){ + String entrada = this.txtIngrese.getText(); + this.lblResultado.setText(this.getSuma(entrada)); + this.txtIngrese.setText(""); + } + +} From 9100638130a011f5a219275817d6f97d1604b1b3 Mon Sep 17 00:00:00 2001 From: PascoDominguez Date: Tue, 17 Oct 2017 17:50:19 -0600 Subject: [PATCH 5/5] EJERCICIOS para 17/10/17 --- EF5.java | 272 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100644 EF5.java diff --git a/EF5.java b/EF5.java new file mode 100644 index 0000000..4119fc8 --- /dev/null +++ b/EF5.java @@ -0,0 +1,272 @@ +import java.io.*; + +public class EF5 { + class Pila { + + class Nodo { + + int dato; + Nodo siguiente; + } + + private Nodo cabeza; + + public Pila() { + cabeza = null; + } + + //************************************************************************// + // PILA // + //************************************************************************// + + public void insetar(int x) { + Nodo nuevo = new Nodo(); + nuevo.dato = x; + if (cabeza == null) { + nuevo.siguiente = null; + cabeza = nuevo; + } else { + nuevo.siguiente = cabeza; + cabeza = nuevo; + } + } + + public int extraer() { + if (cabeza != null) { + int dato = cabeza.dato; + cabeza = cabeza.siguiente; + return dato; + } else { + return Integer.MAX_VALUE; + } + } + + public void imprimirPila() { + Nodo pila = cabeza; + while (pila != null) { + System.out.print(pila.dato + ", "); + pila = pila.siguiente; + } + System.out.println(""); + } + +} + + class Cola { + + class Nodo { + + public int dato; + public Nodo siguiente; + public Nodo anterior; + + } + + private Nodo cabeza, fondo; + + public Cola() { + cabeza = null; + fondo = null; + } + + boolean vacia(){ + if(cabeza==null){ + return true; + }else{ + return false; + } + } + + public void insertarCola(int x){ + Nodo nuevo = new Nodo(); + nuevo.dato = x; + nuevo.siguiente = null; + if (vacia()) { + cabeza = nuevo; + fondo = nuevo; + }else{ + fondo.siguiente = nuevo; + fondo = nuevo; + } + } + + public int extrarCola(){ + if(!vacia()){ + int info = cabeza.dato; + if (cabeza == fondo) { + cabeza = null; + fondo = null; + }else{ + cabeza = cabeza.siguiente; + } + return info; + }else{ + return Integer.MAX_VALUE; + } + } + + public void imprimirCola(){ + Nodo aux = cabeza; + while(aux!=null){ + System.out.print(aux.dato+", "); + aux = aux.siguiente; + } + } +} + + class ListaCircular { + + class Nodo { + + public int dato; + public Nodo siguiente; + public Nodo anterior; + } + + private Nodo primero; + private Nodo ultimo; + + public ListaCircular(){ + primero = null; + ultimo = null; + } + + public void Insertar_al_final(int x) { + Nodo nuevo = new Nodo(); + nuevo.dato = x; + if(primero == null){ + primero = nuevo; + ultimo = nuevo; + ultimo.siguiente = primero; + }else{ + ultimo.siguiente =nuevo; + nuevo.siguiente = primero; + ultimo = nuevo; + } + } + + public void impirmirListaCircular(){ + Nodo aux = primero; + do{ + System.out.print(aux.dato+", "); + aux = aux.siguiente; + }while(aux!=primero); + System.out.println(""); + } + +} + + class ListaDoble { + class Nodo{ + public int dato; + public Nodo siguiente; + public Nodo anterior; + } + private Nodo primero; + public ListaDoble(){ + primero = null; +} + public void InsetarInicioLD(int x){ + Nodo nuevo = new Nodo(); + nuevo.dato = x; + if(primero == null){ + primero =nuevo; + }else{ + nuevo.siguiente = primero; + primero.anterior = nuevo; + primero = nuevo; + } + } + + public void impirmirLD(){ + Nodo aux = primero; + while(aux!=null){ + System.out.print(aux.dato+", "); + aux = aux.siguiente; + } + System.out.println(""); + } +} + + class LeerArchivo { + public String leerFibonacci(String archivo){ + String texto = ""; + try { + BufferedReader mBuffer = new BufferedReader(new FileReader(archivo)); + String bfReader; + String aux= ""; + while((bfReader = mBuffer.readLine())!= null){ + aux = aux + bfReader; + } + texto = aux; + mBuffer.close(); + } catch (Exception e) { + }return texto; + + } +} + + void leerArchivo() { + LeerArchivo la = new LeerArchivo(); + String fibonnacci = la.leerFibonacci("C:\\Users\\Pasco Dominguez\\Documents\\NetBeansProjects\\TareaFinal\\archivo.txt"); + System.out.println("FIBONACCI"); + System.out.println(fibonnacci); + String numeros[] = fibonnacci.split(", "); + int n = 0; + + Pila miPila = new Pila(); + Cola cl = new Cola(); + ListaCircular listaC = new ListaCircular(); + ListaDoble ld = new ListaDoble(); + + for (int i = 0; i < numeros.length; i++) { + n = Integer.parseInt(numeros[i]); + miPila.insetar(n); + cl.insertarCola(n); + listaC.Insertar_al_final(n); + ld.InsetarInicioLD(n); + } + System.out.println("-----------------------------------------------------"); + System.out.println("PILA"); + miPila.imprimirPila(); + System.out.println(""); + System.out.println("-----------------------------------------------------"); + System.out.println("COLA"); + cl.imprimirCola(); + System.out.println(""); + System.out.println(""); + System.out.println("-----------------------------------------------------"); + System.out.println("LISTA DOBLE (InsertaralFrente)"); + ld.impirmirLD(); + System.out.println(""); + System.out.println(""); + System.out.println("-----------------------------------------------------"); + System.out.println("LISTA CIRCULAR (InsertaralFinal)"); + listaC.impirmirListaCircular(); + + } + + void escribirArchivo() { + File archivo; + String fibonacci = "0, 1, 1, 2, 5, 8, 13, 21, 34, 55, 89"; + try { + archivo = new File("archivo.txt"); + if (archivo.createNewFile()) { + System.out.println("se ha creado el archivo"); + FileWriter escribir = new FileWriter(archivo); //escribir en una sola linea de texto + PrintWriter linea = new PrintWriter(escribir);//para esccribir en varias lineas de texto + linea.println(fibonacci); + linea.close(); + escribir.close(); + } + } catch (IOException e) { + System.out.println("No se ha podido crear el archivo" + e); + } + } + + public static void main(String[] args) { + EF5 tad = new EF5(); + tad.escribirArchivo(); + tad.leerArchivo(); + } +}