Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TareaFinal_201403504 #10

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions EF1.java

This file was deleted.

9 changes: 0 additions & 9 deletions EF2.java

This file was deleted.

91 changes: 91 additions & 0 deletions EF4.java
Original file line number Diff line number Diff line change
@@ -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("");
}

}
272 changes: 272 additions & 0 deletions EF5.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading