Mostrando entradas con la etiqueta Taller de POO Puntos Extras. Mostrar todas las entradas
Mostrando entradas con la etiqueta Taller de POO Puntos Extras. Mostrar todas las entradas

miércoles, 23 de noviembre de 2011

Patrones de Diseño

Bebida Cafeinada
 
public abstract class BebidaCafeinada
{
 public final void prepararReceta()
 {
  hervir();
  poner();
  servir();
  agregarCondimentos();
  System.out.println();
 }

 public abstract void poner();
 public abstract void agregarCondimentos();

 public void hervir()
 {
  System.out.println("Hirviendo agua. ");
 }

 public void servir()
 {
  System.out.println("Sirviendo.");
 }
}
 
public class Te extends BebidaCafeinada
{
 public void poner()
 {
  System.out.println("Poniendo Té.");
 }

 public void agregarCondimentos()
 {
  System.out.println("Agregando limón.");
 }
}

Café
 
public class Cafe extends BebidaCafeinada
{
 public void poner()
 {
  System.out.println("Poniendo café.");
 }

 public void agregarCondimentos()
 {
  System.out.println("Agregando Azucar y Leche.");
 }
}

Prueba Bebidas
 
public class PruebaBebidas
{
 public static void main(String[] args)
 {
  Te te1 = new Te();
  Cafe cafe1 = new Cafe();

  System.out.println("Preparando té.");
  te1.prepararReceta();

  System.out.println("Preparando Café.");
  cafe1.prepararReceta();
 }
}

Autogeneración de código juego

Para realizar la autogeneración de código utilice la herramienta de Umbrello


Atacable
 
/**
 * Interface Atacable
 */
public interface Atacable {

  //
  // Fields
  //

  
  //
  // Methods
  //


  //
  // Accessor methods
  //

  //
  // Other methods
  //

  /**
   * @param        a
   */
  public void atacar( Atacable a );


  /**
   * @param        intensidad
   */
  public void recibirAtaque( int intensidad );


}

Capturable
 

/**
 * Interface Capturable
 */
public interface Capturable {

  //
  // Fields
  //

  
  //
  // Methods
  //


  //
  // Accessor methods
  //

  //
  // Other methods
  //

  /**
   */
  public void capturar(  );


  /**
   */
  public void liberar(  );


}
/**
 * Interface Capturable
 */
public interface Capturable {

  //
  // Fields
  //

  
  //
  // Methods
  //


  //
  // Accessor methods
  //

  //
  // Other methods
  //

  /**
   */
  public void capturar(  );


  /**
   */
  public void liberar(  );


}

Congelable
 

/**
 * Interface Congelable
 */
public interface Congelable {

  //
  // Fields
  //

  
  //
  // Methods
  //


  //
  // Accessor methods
  //

  //
  // Other methods
  //

  /**
   */
  public void congelar(  );


}

Curable
 

/**
 * Interface Curable
 */
public interface Curable {

  //
  // Fields
  //

  
  //
  // Methods
  //


  //
  // Accessor methods
  //

  //
  // Other methods
  //

  /**
   * @return       int
   */
  public int curar(  );


}

Mago
 

import java.util.*;


/**
 * Class Mago
 */
public class Mago extends Personaje {

  //
  // Fields
  //

  
  //
  // Constructors
  //
  public Mago () { };
  
  //
  // Methods
  //


  //
  // Accessor methods
  //

  //
  // Other methods
  //

  /**
   * @param        c
   */
  public void lanzarHechizo( Congelable c )
  {
  }


  /**
   * @param        c
   */
  public void curar( Curable c )
  {
  }


}
Ogro
 

import java.util.*;


/**
 * Class Ogro
 */
public class Ogro extends PersonajeAtacable implements Capturable, Congelable {

  //
  // Fields
  //

  private boolean congelado = false;
  
  //
  // Constructors
  //
  public Ogro () { };
  
  //
  // Methods
  //


  //
  // Accessor methods
  //

  /**
   * Set the value of congelado
   * @param newVar the new value of congelado
   */
  private void setCongelado ( boolean newVar ) {
    congelado = newVar;
  }

  /**
   * Get the value of congelado
   * @return the value of congelado
   */
  private boolean getCongelado ( ) {
    return congelado;
  }

  //
  // Other methods
  //

  /**
   * @param        c
   */
  public void capturar( Capturable c )
  {
  }


  /**
   */
  public void capturar(  )
  {
  }


  /**
   */
  public void liberar(  )
  {
  }


  /**
   */
  public void congelar(  )
  {
  }


}

Personaje
 


/**
 * Class Personaje
 */
public class Personaje {

  //
  // Fields
  //

  private String nombre;
  
  //
  // Constructors
  //
  public Personaje () { };
  
  //
  // Methods
  //


  //
  // Accessor methods
  //

  /**
   * Set the value of nombre
   * @param newVar the new value of nombre
   */
  private void setNombre ( String newVar ) {
    nombre = newVar;
  }

  /**
   * Get the value of nombre
   * @return the value of nombre
   */
  private String getNombre ( ) {
    return nombre;
  }

  //
  // Other methods
  //

}
Personaje Atacable
 

/**
 * Class PersonajeAtacable
 */
public class PersonajeAtacable extends Personaje implements Atacable {

  //
  // Fields
  //

  static private int DEFAULT_VIDA = 100;
  private int vida;
  
  //
  // Constructors
  //
  public PersonajeAtacable () { };
  
  //
  // Methods
  //


  //
  // Accessor methods
  //

  /**
   * Get the value of DEFAULT_VIDA
   * @return the value of DEFAULT_VIDA
   */
  private int getDEFAULT_VIDA ( ) {
    return DEFAULT_VIDA;
  }

  /**
   * Set the value of vida
   * @param newVar the new value of vida
   */
  private void setVida ( int newVar ) {
    vida = newVar;
  }

  /**
   * Get the value of vida
   * @return the value of vida
   */
  private int getVida ( ) {
    return vida;
  }

  //
  // Other methods
  //

  /**
   * @param        cuanta
   */
  public void restarVida( int cuanta )
  {
  }


  /**
   * @param        a
   */
  public void atacar( Atacable a )
  {
  }


  /**
   * @param        intensidad
   */
  public void recibirAtaque( int intensidad )
  {
  }


}
Princesa
 


/**
 * Class Princesa
 */
public class Princesa extends Personaje implements Capturable {

  //
  // Fields
  //

  private String status = "libre";
  
  //
  // Constructors
  //
  public Princesa () { };
  
  //
  // Methods
  //


  //
  // Accessor methods
  //

  /**
   * Set the value of status
   * @param newVar the new value of status
   */
  private void setStatus ( String newVar ) {
    status = newVar;
  }

  /**
   * Get the value of status
   * @return the value of status
   */
  private String getStatus ( ) {
    return status;
  }

  //
  // Other methods
  //

  /**
   */
  public void capturar(  )
  {
  }


  /**
   */
  public void liberar(  )
  {
  }


}
Principe
 

import java.util.*;


/**
 * Class Principe
 */
public class Principe extends PersonajeAtacable implements Curable {

  //
  // Fields
  //

  
  //
  // Constructors
  //
  public Principe () { };
  
  //
  // Methods
  //


  //
  // Accessor methods
  //

  //
  // Other methods
  //

  /**
   * @return       Mago
   */
  public Mago invocarMago(  )
  {
  }


  /**
   * @param        o
   */
  public void atacar( Ogro o )
  {
  }


  /**
   * @param        c
   */
  public void rescatar( Capturable c )
  {
  }


  /**
   * @return       int
   */
  public int curar(  )
  {
  }


}

Ejercicios SQL

Ejercicio A


SELECT City, CompanyName
FROM customers
WHERE City LIKE 'ber%'

Ejercicio B


SELECT CompanyName, ContactName
FROM customers
ORDER BY ContactName

Ejercicio C



SELECT COUNT(ContactName)
FROM customers
WHERE ContactName LIKE 'Ma%'
Ejercicio D

SELECT ContactName, City
FROM customers
WHERE ContactName LIKE 'g%'
AND City LIKE 'b%'

Ejercicio A



SELECT Materias.Materia, Count(Calificaciones.Clave)
FROM Materias, Calificaciones
WHERE Materias.Clave = Calificaciones.Clave
GROUP BY Materia

Ejercicio B



SELECT Materias.Materia, Calificaciones.Calificacion
FROM Materias, Calificaciones
WHERE Clave.Materias = Clave.Calificaciones
HAVING Calificaciones  > 76
ORDER BY Calificaciones 

miércoles, 31 de agosto de 2011

Ejemplo Moto

Clase Moto
public class Moto {
   //atributos
   private String placa;
   private boolean edoMotor;
   private int velocidad;
   private int vidaBateria;
   
   //constructor
   public Moto(String placa, boolean edoMotor, int velocidad, int vidaBateria)
   {
       this.placa = placa;
       this.edoMotor = edoMotor;
       this.velocidad = velocidad;
       this.vidaBateria = vidaBateria;
   }

   //métodos
   public String verPlaca ()
   {
       return placa;
   }
   
   public void encender()
   {
       edoMotor = true;
       if(vidaBateria>=0)
       {
           vidaBateria--;
       }
       
   }
   
   public void apagar()
   {
       edoMotor = false;
       velocidad = 0;
   }
   
   public void acelerar()
   {
       if(edoMotor = true)
       {
           velocidad = velocidad + 20;
       }
   }
   
   public void frenar ()
   {
       if(edoMotor = true && velocidad > 0)
       {
           velocidad = velocidad - 20;
       }
   }
   
   public void descMoto()
   {
       System.out.println("La placa es: "+placa);
       if(edoMotor == false){
       System.out.println("El motor esta apagado");
       }
       else {
       System.out.println("El motor esta encendido");
      }
       System.out.println("La velocidad es: "+velocidad);
       System.out.println("La vida de la Bateria es: "+vidaBateria);
       System.out.println("\n\n");
   }
}

Clase RunMoto

import java.util.Scanner;

public class RunMoto
{
   public static void main (String[] args)
   {
       
       Moto moto1 = new Moto("I4F230", false, 0, 100);
       
       int opcion = 0;
       Scanner read = new Scanner(System.in);
       
       do
       {
       System.out.println("1.-Describir Moto");
       System.out.println("2.-Encender Motor");
       System.out.println("3.-Apagar Motor");
       System.out.println("4.-Acelerar");
       System.out.println("5.-Frenar");
       System.out.println("6.- Salir\n");
                                   
       System.out.print("Ingrese: ");
       opcion = read.nextInt();
       System.out.println("\n");
       switch(opcion)
       {
           case 1:
               moto1.descMoto();
               break;
           case 2:
               moto1.encender();
               break;
           case 3:
                moto1.apagar();
               break;
           case 4:
               moto1.acelerar();
               break;
           case 5:
               moto1.frenar();
               break;
	 
       }
       }
while(opcion != 6);
   }
}


Programa realizado en equipo con mi compañero Sergio Rdz