Exposiciones

En esta sección se resolverán dudas relacionadas con el lenguaje de programación de Oracle Java

Moderator: julianmartinez16

User avatar
xacarana
Site Admin
Posts: 1028
Joined: Fri Jan 15, 2016 6:13 pm

Exposiciones

Post by xacarana » Tue Jan 31, 2017 8:42 am

Novedades de java

Image Image Image
  • Colecciones (Yenifer)
  • Timer (Juan Jose)
  • Enumeraciones (Valeria)
  • Expresiones lambda (Cristian)
  • Nuevos métodos (Julián)
  • Ciclos (Sebastián)
Patrones

Les recomiendo preparar la exposición usando alguno de estos libros

Image Image
  • Observador (Yenifer)
  • Adaptador (Juan Jose)
  • Builder (Valeria)
  • Singleton (Cristian)
  • Comando (Julián)
  • Decorador (Sebastián)
Andrés Bedoya Tobón
Profesor
"I only smile in the dark, I only smile when it's complicated" Raybiez

User avatar
Yenifer Barco
Posts: 44
Joined: Tue Jan 17, 2017 8:57 am

Re: Exposiciones

Post by Yenifer Barco » Tue Feb 07, 2017 8:17 am



http://www.slideshare.net/YeniferCastri ... s-73226912

ejemplo collections:

Code: Select all

public class Persona {

	private String nombre;
	private int edad;

	public Persona() {
	}

	public Persona(String nombre, int edad) {
	this.nombre = nombre;
	this.edad = edad;
	}

	public String getNombre() {
	return nombre;
	}

	public void setNombre(String nombre) {
	this.nombre = nombre;
	}

	public int getEdad() {
	return edad;
	}

	public void setEdad(int edad) {
	this.edad = edad;
	}

	@Override
	public String toString() {
	return this.getNombre() + " ‐ " + this.getEdad();
	}
}
menu

Code: Select all

import java.util.*;
public class Menu{
	
	public static void main (String args[]){

		/*Supongamos que tenemos un ArrayList llamado "personas" con los siguientes objetos de la clase persona:*/
		private static ArrayList personas = new ArrayList<>();
		
		personas.add(new Persona("Pepe", 28));
		personas.add(new Persona("Juan", 32));
		personas.add(new Persona("Paco", 40));
		personas.add(new Persona("Susi", 24));
		personas.add(new Persona("Lola", 20));
		personas.add(new Persona("Jose", 28));
		personas.add(new Persona("Dani", 24));
		personas.add(new Persona("Sara", 36));

		/*Este ArrayList lo queremos ordenar (de menor a mayor edad) en función de la edad de las personas, por tanto tenemos que sobre escribir el método
		"compare" de la clase Comparator y llamar al método "sort" de la clase collections. Esto lo hacemos de la siguiente forma:*/

		Collections.sort(personas, new Comparator() {
		@Override
		public int compare(Persona p1, Persona p2) {
		return new Integer(p1.getEdad()).compareTo(new Integer(p2.getEdad()));
		}
		});


		/*Si ahora queremos ordenarlo de mayor a menor edad, solo tenemos que cambiar el método "compare" poniendo la comparación al revés:*/

		Collections.sort(personas, new Comparator() {
		@Override
		public int compare(Persona p1, Persona p2) {
		// Aqui esta el truco, ahora comparamos p2 con p1 y no al reves como antes
		return new Integer(p2.getEdad()).compareTo(new Integer(p1.getEdad()));
		}
		});

		/*Este nos permite eliminar un eleento en especifico, en este caso a pepe*/
		Persona.removeIf(p ->p getNombre().equals("Pepe"));
		for(Persona p:personas){
			System.out.println(p.getNombre());
		}
		
	}	
}
Last edited by Yenifer Barco on Thu Mar 16, 2017 5:13 pm, edited 1 time in total.

User avatar
Valeriam04
Posts: 45
Joined: Tue Jan 17, 2017 8:55 am

Novedades de Java Enum

Post by Valeriam04 » Tue Feb 07, 2017 4:46 pm



http://www.slideshare.net/ValeriaMoreno ... -java-enum

Code: Select all


EJEMPLOS

public enum Color
{
	Blanco,Negro, Gris
};

Code: Select all


import javax.swing.JOptionPane;

public static void main(String[] args) 
{

	/*
	 * CREACION DE LA SECADORA
	*/
	Secadora[] bodega_secadoras = new Secadora[200];
		
	public static Secadora PedirDatosSecadora(Secadora[] bodega_secadoras)
	{
		int secadoras = 0;
		String codigo = JOptionPane.showInputDialog(null, " Ingrese el codigo de la SECADORA ");
		int altura = Integer.parseInt(JOptionPane.showInputDialog(" Ingrese la altura de la secadora que desea "));
		int ancho = Integer.parseInt(JOptionPane.showInputDialog(" Ingrese el ancho de la secadora que desea "));
		int profundidad = Integer.parseInt(JOptionPane.showInputDialog(" Ingrese la profundidad de la secadora que desea "));
		double peso_kg = Double.parseDouble(JOptionPane.showInputDialog(" Ingrese el peso que desea para la secadora "));
		double capacidad = Double.parseDouble(JOptionPane.showInputDialog(" Ingrese la capacidad que desea para la secadora "));
		String descripcion = JOptionPane.showInputDialog(null, " Ingrese la descripcion de la SECADORA que desea "); 
		Cliente cliente = new Cliente("", "", "", "",null,"",0);
		Color color = null;
		String Colors = JOptionPane.showInputDialog(null, " Ingrese el color que desea para la secadora");
		
		if(Colors.equals("blanco"))
		{
			color = Color.Blanco;
		}
		
		else if(Colors.equals("negro"))
		{
			color = Color.Negro;
		}
		
		else if(Colors.equals("gris"))
		{
			color = Color.Gris;
		}
		
		Secadora secadora1 = new  Secadora(codigo,capacidad,color,altura,ancho,descripcion,profundidad,peso_kg,cliente);
		bodega_secadoras[secadoras] = secadora1;
		secadoras++;
		return secadora1;
	}
}


Last edited by Valeriam04 on Tue Feb 21, 2017 8:25 am, edited 5 times in total.
Valeria Moreno
Gestión de la calidad del Software

User avatar
jbrandlondoo
Posts: 20
Joined: Thu Jan 26, 2017 7:43 am

Re: Exposiciones

Post by jbrandlondoo » Tue Feb 14, 2017 6:56 am



http://www.slideshare.net/secret/MiH7pMgXqZWqlS

main

Code: Select all

class Timer {

    public static void main(String args[]) {

    Progreso p=new Progreso();

        p.setVisible(true);
    }
}
class

Code: Select all

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;

public class Progreso extends javax.swing.JFrame {
      Timer t;
      ActionListener ac;
   
    public Progreso() {
        
        ac=new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(barrita.getValue()<100){
                barrita.setValue(barrita.getValue()+10);
                }else{t.stop();}
                 }
        };
        t=new Timer(1100,ac);
        initComponents();
        
    }
    
    @SuppressWarnings("unchecked")
    private void initComponents() {

        jProgressBar1 = new javax.swing.JProgressBar();
        jButton1 = new javax.swing.JButton();
        barrita = new javax.swing.JProgressBar();
        boton = new javax.swing.JButton();

        jButton1.setText("jButton1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        boton.setText("iniciar");
        boton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addComponent(barrita, javax.swing.GroupLayout.PREFERRED_SIZE, 352, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(156, 156, 156)
                        .addComponent(boton)))
                .addContainerGap(24, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(boton)
                .addGap(18, 18, 18)
                .addComponent(barrita, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }                    

    private void botonActionPerformed(java.awt.event.ActionEvent evt) {                                      
        
            t.start();
        
    }                        
    private javax.swing.JProgressBar barrita;
    private javax.swing.JButton boton;
    private javax.swing.JButton jButton1;
    private javax.swing.JProgressBar jProgressBar1;
               }  
Last edited by jbrandlondoo on Sat Mar 04, 2017 11:28 am, edited 3 times in total.

User avatar
ccpc
Posts: 60
Joined: Fri Jan 22, 2016 8:08 am

Re: Exposiciones

Post by ccpc » Mon Feb 20, 2017 6:15 pm


https://www.slideshare.net/secret/o79vcGQtE9Rwu0

Code: Select all

import javax.swing.*;
public class Ejemplo
{
	
	public static void main(String[] args) {
	int num1,num2;
	String numero1,numero2;
     numero1=JOptionPane.showInputDialog("ingrese el numero1");
     numero2=JOptionPane.showInputDialog("ingrese el segundo numero");
     if (numero1 != null && numero2!=null && numero1.matches("\\d+") && numero2.matches("\\d+")) {
     	num1=Integer.parseInt(numero1);
     	num2=Integer.parseInt(numero2);
     	Ejemplo1 suma = (a,b)-> a+b;

        System.out.print("su numero es "+suma.ingreseNumeros(num1,num2));
     }
     else
     {
     	System.out.println("datos invalidos");
     }
		
        
        	
        } 
		
		 
		

	}

Code: Select all


public interface Ejemplo1{

	 int ingreseNumeros(int num1,int num2);

}
Nombre: Cristian Camilo Palacio Cuartas.
Materia: Logica de programación.

User avatar
julianreco1
Posts: 46
Joined: Fri Jan 22, 2016 8:09 am

Re: Exposiciones

Post by julianreco1 » Thu Feb 23, 2017 3:34 am


https://es.slideshare.net/julianrestrep ... s-en-java8

codigo implementado

Code: Select all

public class programa
{


public static void main(String args[]) throws InterruptedException{

       Thread juan = new Thread (new Alumno(“Juan”));
       Thread luis = new Thread (new Alumno(“Luis”));
       Thread nora = new Thread (new Alumno(“Nora”));
      
       juan.start();
       	juan.join();

       pepe.start();
		pepe.join();

       jorge.start();
		jorge.join();



 	}
}

Code: Select all

class Alumno implements Runnable{

String mensaje;

public Alumno(String nombre){

      mensaje = “Hola, soy “ + nombre + “ y este es mi mensaje numero: “;

}

public void run(){

      for (int i=1; i<6;i++){
                      String msj = mensaje + i;
                      System.out.println(msj);
      }

}

Code: Select all

public static String join(CharSequence delimiter, CharSequence... elements)

Code: Select all

public static int divideUnsigned(int dividend, int divisor)

Code: Select all

public static int compareUnsigned(int x, int y)

Code: Select all

public static int sum(int a, int b)

Code: Select all

public static int max(int a, int b)
en las diapositivas explico el uso de los threads y de la interfaz running :v :roll:
Julian Restrepo
Programacion Orientada a Objetos - POO
хотят знать, что Ха-ха привет :?

User avatar
sebasvallejoroldan
Posts: 13
Joined: Tue Jan 17, 2017 9:02 am

Re: Exposiciones

Post by sebasvallejoroldan » Tue Feb 28, 2017 4:43 am

Presentación:

https://slides.com/sebastianvallejoroldan/cicloforeach

Ejemplo:

Code: Select all

public class ForEach {

	public static void main(String[] args) {
		
		int[] vector = {2,4,6,8,10};
		
		for(int elemento : vector) {

			System.out.println(elemento);
		}
	}

}

User avatar
Valeriam04
Posts: 45
Joined: Tue Jan 17, 2017 8:55 am

Buider desing Patern

Post by Valeriam04 » Mon Mar 06, 2017 11:49 am



https://www.slideshare.net/ValeriaMoren ... ing-patern

Code: Select all

/** "Producto" */
class Pizza 
{
    private String masa = "";
    private String salsa = "";
    private String relleno = "";
 
    public void setMasa(String masa)
    { 
	this.masa = masa; 
    }

    public void setSalsa(String salsa)     
    { 
	this.salsa = salsa; 
    }

    public void setRelleno(String relleno) 
    { 
	this.relleno = relleno; 
    }
}
 

Code: Select all

/** "Abstract Builder" */
abstract class PizzaBuilder 
{
    protected Pizza pizza;
 
    public Pizza getPizza() 
    { 
	return pizza; 
    }

    public void crearNuevaPizza() 
    {
	 pizza = new Pizza(); 
    }
 
    public abstract void buildMasa();
    public abstract void buildSalsa();
    public abstract void buildRelleno();

}

Code: Select all

/** "ConcreteBuilder" */
class HawaiPizzaBuilder extends PizzaBuilder 
{
    public void buildMasa()   
   { 
	pizza.setMasa("suave"); 
   }

    public void buildSalsa()   
    {
	 pizza.setSalsa("dulce"); 
    }

    public void buildRelleno() 
    { 
	pizza.setRelleno("chorizo+alcachofas"); 
    }
}
 
/** "ConcreteBuilder" */
class PicantePizzaBuilder extends PizzaBuilder 
{
    public void buildMasa()   
    { 
	pizza.setMasa("cocida"); 
    }

    public void buildSalsa()   
    { 
	pizza.setSalsa("picante"); 
    }

    public void buildRelleno() 
    {
	pizza.setRelleno("pimienta+salchichón"); 
    }
}
 

Code: Select all

/** "Director" */
class Cocina 
{
    private PizzaBuilder pizzaBuilder;
 
    public void setPizzaBuilder(PizzaBuilder pb) 
    {
	 pizzaBuilder = pb; 
    }

    public Pizza getPizza() 
    {
	 return pizzaBuilder.getPizza(); 
    }
 
    public void construirPizza() 
    {
       pizzaBuilder.crearNuevaPizza();
       pizzaBuilder.buildMasa();
       pizzaBuilder.buildSalsa();
       pizzaBuilder.buildRelleno();
    }
}

Code: Select all

/** Un cliente pidiendo una pizza. */
class BuilderExample 
{
    public static void main(String[] args) {
        Cocina cocina = new Cocina();
        PizzaBuilder hawai_pizzabuilder = new HawaiPizzaBuilder();
        PizzaBuilder picante_pizzabuilder = new PicantePizzaBuilder();
 
        cocina.setPizzaBuilder( hawai_pizzabuilder );
        cocina.construirPizza();
 
        Pizza pizza = cocina.getPizza();
    }
}
Valeria Moreno
Gestión de la calidad del Software

User avatar
Yenifer Barco
Posts: 44
Joined: Tue Jan 17, 2017 8:57 am

Re: Exposiciones

Post by Yenifer Barco » Wed Mar 08, 2017 11:28 pm

Observer Design Pattern



http://www.slideshare.net/YeniferCastri ... n-72971154

Ejemplo 1:

Clase Observer

Code: Select all

public abstract class Observer {
   protected Subject subject;
   public abstract void update();
}
Clase Subject

Code: Select all

import java.util.ArrayList;
import java.util.List;

public class Subject {
	
   private List<Observer> observers = new ArrayList<Observer>();
   private int state;

   public int getState() {
      return state;
   }

   public void setState(int state) {
      this.state = state;
      notifyAllObservers();
   }

   public void attach(Observer observer){
      observers.add(observer);		
   }

   public void notifyAllObservers(){
      for (Observer observer : observers) {
         observer.update();
      }
   } 	
}
Clase OctalObserver

Code: Select all

public class OctalObserver extends Observer{

   public OctalObserver(Subject subject){
      this.subject = subject;
      this.subject.attach(this);
   }

   @Override
   public void update() {
     System.out.println( "Octal String: " + Integer.toOctalString( subject.getState() ) ); 
   }
}
Clase HexaObserver

Code: Select all

public class HexaObserver extends Observer{

   public HexaObserver(Subject subject){
      this.subject = subject;
      this.subject.attach(this);
   }

   @Override
   public void update() {
      System.out.println( "Hex String: " + Integer.toHexString( subject.getState() ).toUpperCase() ); 
   }
}
Clase BinaryObserver

Code: Select all

public class BinaryObserver extends Observer{

   public BinaryObserver(Subject subject){
      this.subject = subject;
      this.subject.attach(this);
   }

   @Override
   public void update() {
      System.out.println( "Binary String: " + Integer.toBinaryString( subject.getState() ) ); 
   }
}
Clase ObserverPatternDemo

Code: Select all

public class ObserverPatternDemo {
   public static void main(String[] args) {
      Subject subject = new Subject();

      new HexaObserver(subject);
      new OctalObserver(subject);
      new BinaryObserver(subject);

      System.out.println("First state change: 15");	
      subject.setState(15);
      System.out.println("Second state change: 10");	
      subject.setState(10);
   }
}
Ejemplo 2

Interfaz Subject

Code: Select all

interface Subject {
       public void registerObserver(Observer observer);
       public void removeObserver(Observer observer);
       public void notifyObservers();
}
Interfaz Observer

Code: Select all

public abstract class Observer {
   protected Subject subject;
   public abstract void update();
}
Clase Loan

Code: Select all

import java.util.ArrayList;

class Loan implements Subject {
       private ArrayList<Observer> observers = new ArrayList<Observer>();
       private String type;
       private float interest;
       private String bank;

       public Loan(String type, float interest, String bank) {
              this.type = type;
              this.interest = interest;
              this.bank = bank;
       }

       public float getInterest() {
              return interest;
       }
    public void setInterest(float interest) {
              this.interest = interest;
              notifyObservers();
       }

       public String getBank() {
              return this.bank;
       }

       public String getType() {
              return this.type;
       }

       @Override
       public void registerObserver(Observer observer) {
              observers.add(observer);

       }

       @Override
       public void removeObserver(Observer observer) {
              observers.remove(observer);

       }

       @Override
       public void notifyObservers() {
              for (Observer ob : observers) {
                     System.out
                                  .println("Notificación a los observadores sobre el cambio en la tasa de interés del préstamo");
                     ob.update(this.interest);
              }
       }
}
Clase Internet

Code: Select all

class Internet implements Observer {
       @Override
       public void update(float interest) {
              System.out.println("Internet: Tasa de interes actualizada, nueva tasa de interes es: "
                           + interest);
       }
}
Clase Newspaper

Code: Select all

class Newspaper implements Observer {
       @Override
       public void update(float interest) {
              System.out.println("Newspaper: Tasa de interes actualizada, nueva tasa es: "
                           + interest);
       }
}
Clase ObseverTest

Code: Select all

public class ObserverTest {

       public static void main(String args[]) {
              // this will maintain all loans information
              Newspaper printMedia = new Newspaper();
              Internet onlineMedia = new Internet();

              Loan personalLoan = new Loan("Prestamo personal", 12.5f,
                           "Standard Charterd");
              personalLoan.registerObserver(printMedia);
              personalLoan.registerObserver(onlineMedia);
              personalLoan.setInterest(3.5f);

       }
}

User avatar
jbrandlondoo
Posts: 20
Joined: Thu Jan 26, 2017 7:43 am

Re: Exposiciones

Post by jbrandlondoo » Mon Mar 13, 2017 2:10 pm



https://www.slideshare.net/juanjose270/exposision-copia
adaptador caballo

Code: Select all

public class AdaptadorCaballo extends Caballo
{
	Vehiculo vehiculo = new Vehiculo();
	
	public void adaptar()
	{
		vehiculo.moverse("se mueve en 4 patas sobre la tierra ");
		vehiculo.trasportar("trasporta 1 personas");
	}
}
animal

Code: Select all

public abstract class Animal
{
	public abstract void alimentarse();
	public abstract void dormir();
	public abstract void respirar();
}
caballo

Code: Select all

public class Caballo extends Animal
{
	@Override
	public void alimentarse()
	{
		System.out.println("el caballo se esta alimentando");
	}

	@Override
	public void dormir()
	{
		System.out.println("el caballo esta durmiendo");
	}
	
	@Override
	public void respirar()
	{
		System.out.println("el caballo esta respirando");
	}
}

Code: Select all

public class MediosTrasporte
{
	public static void main(String args[])
	{
		Caballo caballo;
		AdaptadorCaballo adc;
		Moto moto;

		caballo = new Caballo();
		adc = new AdaptadorCaballo();
		moto = new Moto();

		System.out.println("_______caballo_______");
		caballo.alimentarse();
		caballo.dormir();
		caballo.respirar();
		System.out.println("_______adaptadorCaballo_______");
		adc.alimentarse();
		adc.dormir();
		adc.respirar();
		adc.adaptar();
		System.out.println("_______moto_______");
		moto.cargarCombustible("la moto esta cargando combustible");
		moto.moverse("se mueve sobre la tierra en dos llantas");
		moto.trasportar("la moto trasporta maximo dos personas legalmente");
	}
}

Code: Select all

public class Moto extends Vehiculo
{

}

Code: Select all

public class Vehiculo
{
	public void cargarCombustible(String a)
	{
		System.out.println(a);
	}
	public void moverse(String b)
	{
		System.out.println(b);
	}
	public void trasportar(String c)
	{
		System.out.println(c);
	}
} 
Last edited by jbrandlondoo on Thu Mar 16, 2017 8:13 am, edited 1 time in total.

Post Reply