PROGRAMACION ORIENTADA A OBJETOS

Aquí están los programas que se expusieron el 24 de febrero
__________________________________________________________________________________
package saludo;

/**
 *
 * @author XMV
 * Instituto Tecnológico Milpa Alta II
 * PROGRAMA PARA VER COMO SE PUEDE DAR FORMATO A UN TEXTO
 */
public class Saludo {
p
    /**
     * MAIN INDICA EL INICIO MÉTODO DE LA APLICACIÓN EN JAVA
     */
    public static void main(String[] args)
    {
        System.out.printf("%s\n%s\n", "Bienvenido a", "Programar con JAVA");
    }//TERMINA EL MÉTODO MAIN
}//FINALIZA LA CLASE SALUDO







_____________________________________________________________________________

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package saludo2;

/**
 *
 * @author XMV
 * Instituto Tecnológico Milpa Alta II
 * Programación Orientada a Objetos
 */
import java.util.Scanner; //utilizaremos la clase Scanner
public class Saludo2
{
//empieza el método main
    public static void main(String[] args)
    {
        //declaramos un nuevo objeto de la clase Scanner para guardar un dato
        Scanner nombre = new Scanner(System.in);
       
        String entrada;
       
        System.out.print("¿Cómo te llamas? ");
        entrada = nombre.nextLine();
        System.out.println("\nHOLA "+ entrada);
    }
}
___________________________________________________________________________________

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package actividadesdiarias;

/**
 *
 * @author XMV
 * PROGRAMA PARA IMPRIMIR UN EJEMPLO DE ALGORITMO DE
 * ACTIVIDADES DIARIAS
 */
public class ActividadesDiarias {

    //INICIA EL MÉTODO PRINCIPAL
    public static void main(String[] args)
    {
        System.out.printf("%s\t%s\n", "4:30", "DESPERTAR Y PREPARAR DESAYUNO");
        System.out.printf("%s\t%s\n", "5:00", "EJERCICIO");
        System.out.printf("%s\t%s\n", "6:00", "BAÑAR Y DESAYUNAR");
        System.out.printf("%s\t%s\n", "7:40", "SALIR DE LA CASA");
        System.out.printf("%s\t%s\n", "7:00", "TRABAJAR O ESTUDIAR");
        System.out.printf("%s\t%s\n", "14:00", "SALIR DEL TRABAJO");
        System.out.printf("%s\t%s\n", "15:00", "LLEGAR A CASA");
        System.out.printf("%s\t%s\n", "15:30", "COMER");
        System.out.printf("%s\t%s\n", "16:30", "SALIR A AYUDAR");
        System.out.printf("%s\t%s\n", "17:30", "ACTIVIDADES DEL TRABAJO O ESCUELA");
        System.out.printf("%s\t%s\n", "19:30", "PREPARAR LO DEL DIA SIGUIENTE");
        System.out.printf("%s\t%s\n", "20:30", "CENAR");
        System.out.printf("%s\t%s\n", "21:30", "DORMIR O ESTUDIAR");
    }
}
___________________________________________________________________________________
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejemplo_2;

/**
 *
 * @author XMV
 * Instituto Tecnológico Milpa Alta II
 * Programación Orientada a Objetos
 */
public class Ejemplo_2
{
//Manejo de operadores incremento y decremento ++ --
    public static void main (String[] args)
    {
      int i=1;
      prt("i: "+i);
      prt("++1: "+ ++i);
    //Pre-incremento, primero incrementa y luego lo muestra en pantalla
      prt("i++: "+ i++);
    //Post-incremento, primero muestra el 2 y luego incrementa a 3
      prt("i: "+ i);//muestra el 3
      prt("--i: "+ --i);
    //Pre-decremento, primero decrementa i y luego lo muestra
      prt("i-- : "+ i--);
    //Post-decremento, primero muestra i y luego decrementa su valor en 1
      prt("i : "+i);//Ahora i vale 1
    }
    static void prt(String s)
    {
      System.out.println(s);
    //Estas últimas instrucciones son para utilizar prt que nos permite mostrar cadenas de caracteres
    //en pantalla ahorrandonos el System.out.println
    }
}
_________________________________________________________________________________

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejemplo_4;

import java.util.Random;

/**
 *
 * @author X
 * Instituto Tecnológico Milpa Alta II
 * Programación Orientada a Objetos
 */
public class Ejemplo_4
{
public static void main(String[] args)
    {
//Creacion de un objeto tipo Random almacenando un puntero a el en la variable rand
      Random rand=new Random();
//Se generan dos números aleatorio entre 0 y 100
      int i= rand.nextInt() % 100;
      int j= rand.nextInt() % 100;
      prt("i = "+ i);
      prt("j = "+ j);
//Imprime diversas operaciones binarias sobre i y j, junto con su resultado
      prt("i = " + i+ "  j = "+j);
      prt("i > j es "+ (i>j));
      prt("i < j es "+ (i<j));
      prt("i >= j es " + (i>=j));
      prt("i <= j es " + (i<=j));
      prt("i == j es " + (i==j));
      prt("i != j es " + (i!=j));
      prt("(i < 10) && (j < 10) es " + ((i<10)&&(j<10)));
      prt("(i < 10) || (j < 10) es " + ((i<10)||(j<10)));
    }
    static void prt(String s)
    {
      System.out.println(s);
    }
}
___________________________________________________________________________________

package multiplicacionenventanas;


import javax.swing.JOptionPane;
//** Autor xmv
/*Instituto Tecnológico Milpa Alta II
 * Programación Orientada a Objetos
 */
public class MultiplicacionenVentanas {

   public static void main( String args[] )
   {
      int x;       // Primer número declarado como entero
      int y;       // Segundo número declarado como entero
      int z;       // Tercer número declarado como entero
      int resultado;  // Aquí se guardará el resultado

      String xVal;  // primera cadena declarada por el usuario
      String yVal;  // segunda cadena declarada por el usuario
      String zVal;  // Tercera cadena declarada por el usuario

      xVal = JOptionPane.showInputDialog( "Introduzca el primer número:" );
      yVal = JOptionPane.showInputDialog( "Introduzca el segundo número:" );
      zVal = JOptionPane.showInputDialog( "Introduzca el tercer número" );

      x = Integer.parseInt( xVal );//convertimos el dato String en entero
      y = Integer.parseInt( yVal );
      z = Integer.parseInt( zVal );

      resultado = x * y * z;//Hacemos la multiplicación

      JOptionPane.showMessageDialog( null, "El resultado la multiplicación es: "
              + resultado );

      System.exit( 0 );

   } // fin del método main

} // fin de la clase


_________________________________________________________________________________

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package calculadora;
//* Autor xmv
/* Instituto Tecnológico Milpa Alta II
 * POO
 */
class Servo {
  int suma(int x, int y) {
   return (x + y);
  }

  float suma(float x, float y) {
   return (x + y);
  }
}

public class Calculadora {
  public static void main(String[] args) {
   int operacion1;
   float operacion2;

   Servo sumador = new Servo();
   operacion1 = sumador.suma(2,3);
   operacion2 = sumador.suma(0.23F, 12.53F);

   System.out.println("La suma de los enteros 2 y 3 es " + operacion1);
   System.out.println("Sumando 0.23 y 12.53, se consigue " + operacion2);
  }
}

No hay comentarios:

Publicar un comentario