Vous êtes sur la page 1sur 8

Act 6: Trabajo Colaborativo No.

Participante: JANES SAENZ PUERTA Cod. 1.046.427.232

Grupo: 301403_39

Tutor: CESAR JIMENEZ.

UNIVERSIDAD NACIONAL ABIERTA Y A DISTANCIA UNAD 2013

INTRODUCCION

Con este trabajo se busca detallar los aspectos ms importantes de las teoras del aprendizaje expuestas en la Unidad 2 del Mdulo de este curso Programacin orientada a objeto.

PUNTO 1/ Trabajar un programa en JAVA (JCreatorV3 LE) con Una base de Datos teniendo en cuenta que tenga entidad relacin /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package base.de.datos; /** * * @author Softsaenz s.a.s */ import java.sql.*; import javax.swing.*; public class BaseDeDatos { private Connection con=null;//variable para realizar la conexion con la bd JPanel panel;//panel para poder recibir en dnde mostrar los errores //constructor que se encarga de obtener el panel public BaseDeDatos(JPanel vent) { this.panel=vent; } //este metodo devuelve la conexion realizada con la base de datos public Connection getCon() { return con; } //este metodo se encarga de realizar la conexion public void setCon(String name, String user, String psw) { //cargar el driver try { Class.forName("com.mysql.jdbc.Driver"); //si el driver carga correctamente intento conectarme con la bd try { con=DriverManager.getConnection("jdbc:mysql://localhost:3306/"+name, user,psw); }//fin del segundo try catch (Exception e) { JOptionPane.showMessageDialog(panel, "Error 002 ==> No se realiz la conexion"+ "\n"+e.getMessage(),"Error",JOptionPane.ERROR_MESSAGE); } }//fin del primero try catch (Exception e) {

JOptionPane.showMessageDialog(panel, "Error 001 ==> No se cargo el driver"+ "\n"+e.getMessage(),"Error",JOptionPane.ERROR_MESSAGE); } }//fin del metodo de conexion //todo get deben retornar (return) con un tipo de variable, no tiene parmetros //ejemplo: return con //set no retornan y son vacios, tiene parmetros }//fin de la clase PUNTO2/ Trabajar un programa en JAVA (JCreatorV3 LE) que genere un chat entre Cliente

Servidor /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package generar.un.chat; /** * * @author Softsaenz s.a.s */ import java.net.*; import java.io.*; import java.awt.*; public class GenerarUnChat extends Frame implements Runnable { protected DataInputStream i; protected DataOutputStream o; protected TextArea output; protected TextField input; protected Thread listener; public GenerarUnChat (String title, InputStream i, OutputStream o) { super (title); this.i = new DataInputStream (new BufferedInputStream (i)); this.o = new DataOutputStream (new BufferedOutputStream (o)); setLayout (new BorderLayout ()); add ("Center", output = new TextArea ()); output.setEditable (false); add ("South", input = new TextField ()); pack (); show (); input.requestFocus (); listener = new Thread (this); listener.start (); } public void run () { try {

while (true) { String line = i.readUTF (); output.appendText (line + "\n"); } } catch (IOException ex) { ex.printStackTrace (); } finally { listener = null; input.hide (); validate (); try { o.close (); } catch (IOException ex) { ex.printStackTrace (); } } } public boolean handleEvent (Event e) { if ((e.target == input) && (e.id == Event.ACTION_EVENT)) { try { o.writeUTF ((String) e.arg); o.flush (); } catch (IOException ex) { ex.printStackTrace(); listener.stop (); } input.setText (""); return true; } else if ((e.target == this) && (e.id == Event.WINDOW_DESTROY)) { if (listener != null) listener.stop (); hide (); return true; } return super.handleEvent (e); } public static void main (String args[]) throws IOException { if (args.length != 2) throw new RuntimeException ("Syntax: ChatClient "); Socket s = new Socket (args[0], Integer.parseInt (args[1])); new ChatClient ("Chat " + args[0] + ":" + args[1], s.getInputStream (), s.getOutputStream ()); }

PUNTO 3/ Trabajar un programa en JAVA (JCreatorV3 LE) que encripte y desencripte un texto numrico o alfabtico /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package encipte.y.desencripte; /** * * @author Softsaenz s.a.s */ import java.math.BigInteger; import java.util.*; public final class EncipteYDesencripte { int tamPrimo; BigInteger n, q, p; BigInteger totient; BigInteger e, d; private int lt; private int i; /** Constructor de la clase EncipteYDesencripte*/ public EncipteYDesencripte(int tamPrimo) { this.tamPrimo = tamPrimo; generaPrimos(); //Genera p y q generaClaves(); //Genera e y d } public void generaPrimos() { p = new BigInteger(tamPrimo, 10, new Random()); do { q = new BigInteger(tamPrimo, 10, new Random()); } while(q.compareTo(p)==0); } public void generaClaves() { // n = p * q n = p.multiply(q); // toltient = (p-1)*(q-1) totient = p.subtract(BigInteger.valueOf(1)); totient = totient.multiply(q.subtract(BigInteger.valueOf(1))); // Elegimos un e coprimo de y menor que n

do { e = new BigInteger(2 * tamPrimo, new Random()); } while((e.compareTo(totient) != -1) || (e.gcd(totient).compareTo(BigInteger.valueOf(1)) != 0)); // d = e^1 mod totient d = e.modInverse(totient); } public BigInteger[] encripta(String mensaje) { int i; byte[] temp = new byte[1]; byte[] digitos = mensaje.getBytes(); BigInteger[] bigdigitos = new BigInteger[digitos.length]; for(i=0; i<bigdigitos.length;i++){ temp[0] = digitos[i]; bigdigitos[i] = new BigInteger(temp); } BigInteger[] encriptado = new BigInteger[bigdigitos.length]; for(i=0; i<bigdigitos.length; i++)encriptado[i] = bigdigitos[i].modPow(e,n); return(encriptado); } /** * Desencripta el texto cifrado usando la clave privada * * @param encriptado Array de objetos BigInteger que contiene el texto cifrado * que ser desencriptado * @return The decrypted plaintext */ public String EncipteYDesencripte (BigInteger[] encriptado) { BigInteger[] desencriptado = new BigInteger[encriptado.length]; for(int i=0; i<desencriptado.length; i++)desencriptado[i] = encriptado[i].modPow(d,n); char[] charArray = new char[desencriptado.length]; for(int i=0; i<charArray.length; i++)charArray[i] = (char) (desencriptado[i].intValue()); return(new String(charArray)); } public BigInteger damep() {return(p);} public BigInteger dameq() {return(q);} public BigInteger dametotient() {return(totient);} public BigInteger damen() {return(n);} public BigInteger damee() {return(e);} public BigInteger damed() {return(d);} }

CONCLUSIONES

Se desarrollaron todos los ejercicios y se aclararon dudas. Se trabajo en grupo para as formar el trabajo final. Los conceptos trabajados en esta unidad, nos proporcionan herramientas fundamentales para afianzar conocimientos relacionados con las matemticas. Se demuestro el nivel de conocimiento adquirido hasta ahora, gracias al modulo

Vous aimerez peut-être aussi