Follow By Email

miércoles, 31 de marzo de 2010

Juego Gato - Java


package gato;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Gato {

    
    public static int matriz[][] = new int [3][3]; 
    public static BufferedReader br =new BufferedReader (new InputStreamReader (System.in));
    public static void main(String[] args) throws IOException {
    
        int turno=1;
        int respuesta=0;
        
    for(int i=0;i<3;i++){
        for(int b=0;b<3;b++){
            
            matriz[i][b]=0;
            System.out.print(matriz[i][b]);
           
        }
        System.out.println("");
    }
    
        System.out.println("-. Juego del Gato .-");
    //inicio del videoJuego Gato ...
    do{
        turno=turno+1;
        
        
    if(turno%2==0){
    llenarMatrizP1();
    
    }else{
        
    llenarMatrizP2();    
    }    
    
    
    mostrarMatriz();
    respuesta=verificarMatriz(respuesta);
    
    
    
    }while(respuesta==0);
    
    }

    
    
    
    
    
    
    private static void mostrarMatriz() {
        for(int i=0;i<3;i++){
        for(int b=0;b<3;b++){
            
            
            System.out.print(matriz[i][b]);
           
        }
        System.out.println("");
    }
    
    }

    private static int verificarMatriz(int respuesta) {
        
       
        int jugadorG=0;
      
        
         /* horizontal primera fila
         *   
         *  111 
         *  000
         *  000
         *
         * 
          */
         
         
            if(matriz[0][0]==1 && matriz[1][0]==1 && matriz[2][0]==1 ){
            jugadorG=1;
            respuesta=1;
            }
            
            if(matriz[0][0]==2 && matriz[1][0]==2 && matriz[2][0]==2 ){
            jugadorG=2;
            respuesta=1;
        }
       
        
         
         /* horizontal segunda fila
         *   
         *  000 
         *  111
         *  000
         *
         * 
          */
        
         
            if(matriz[0][1]==1 && matriz[1][1]==1 && matriz[2][1]==1 ){
            jugadorG=1;
            respuesta=1;
            }
            
            if(matriz[0][1]==2 && matriz[1][1]==2 && matriz[2][1]==2 ){
            jugadorG=2;
            respuesta=1;
        }
       
        
          /* horizontal tercera fila
         *   
         *  000 
         *  000
         *  111
         *
         * 
          */
     


martes, 30 de marzo de 2010

Presupuesto - Python

 1 # -*- coding: utf-8 -*-
 2 class ModeloDePresupuesto:
 3     # Datos comerciales
 4     titulo = "PRESUPUESTO"
 5     encabezado_nombre = "Eugenia Bahit"
 6     encabezado_web = "www.eugeniabahit.com.ar"
 7     encabezado_email = "mail@mail.com"
 8 
 9     # Datos impositivos
10     alicuota_iva = 21
11 
12     # Propiedades relativas al formato
13     divline = "="*80
14 
15     # Setear los datos del cliente
16     def set_cliente(self):
17         self.empresa = raw_input('\tEmpresa: ')
18         self.cliente = raw_input('\tNombre del cliente: ')
19 
20     # Setear los datos básicos del presupuesto
21     def set_datos_basicos(self):
22         self.fecha = raw_input('\tFecha: ')
23         self.servicio = raw_input('\tDescripción del servicio: ')
24         importe = raw_input('\tImporte bruto: $')
25         self.importe = float(importe)
26         self.vencimiento = raw_input('\tFecha de caducidad: ')
27 
28     # Calcular IVA
29     def calcular_iva(self):
30         self.monto_iva = self.importe*self.alicuota_iva/100
31 
32     # Calcula el monto total del presupuesto
33     def calcular_neto(self):
34         self.neto = self.importe+self.monto_iva
35 
36     # Armar el presupuesto
37     def armar_presupuesto(self):
38         """
39             Esta función se encarga de armar todo el presupuesto
40         """
41         txt = '\n'+self.divline+'\n'
42         txt += '\t'+self.encabezado_nombre+'\n'
43         txt += '\tWeb Site: '+self.encabezado_web+' | '
44         txt += 'E-mail: '+self.encabezado_email+'\n'
45         txt += self.divline+'\n'
46         txt += '\t'+self.titulo+'\n'
47         txt += self.divline+'\n\n'
48         txt += '\tFecha: '+self.fecha+'\n'
49         txt += '\tEmpresa: '+self.empresa+'\n'
50         txt += '\tCliente: '+self.cliente+'\n'
51         txt += self.divline+'\n\n'
52         txt += '\tDetalle del servicio:\n'
53         txt += '\t'+self.servicio+'\n\n'
54         txt += '\tImporte: $%0.2f | IVA: $%0.2f\n' % (
55                                   self.importe, self.monto_iva)
56         txt += '-'*80
57         txt += '\n\tMONTO TOTAL: $%0.2f\n' % (self.neto)
58         txt += self.divline+'\n'
59         print txt 
60 
61     # Método constructor
62     def __init__(self):
63         print self.divline
64         print "\tGENERACIÓN DEL PRESUPUESTO"
65         print self.divline
66         self.set_cliente()
67         self.set_datos_basicos()
68         self.calcular_iva()
69         self.calcular_neto()
70         self.armar_presupuesto()
71 
72 # Instanciar clase
73 presupuesto = ModeloDePresupuesto()

lunes, 29 de marzo de 2010

Mover objeto - ActionScript 3

 1 package  {
 2  
 3  import flash.display.MovieClip;
 4  
 5  
 6  public class main extends MovieClip {
 7   
 8   public var pelota1:pelota;
 9   
10   public function main() {
11    pelota1=new pelota();
12    pelota1.cambioXY();
13    //pelota1.escuchador();
14    
15    addChild(pelota1);
16    pelota1.escuchador2();
17   }
18  }
19  
20 }

Sinónimos y antónimos - Java

 1 package sinonimosantonimos;
 2 
 3 import java.io.BufferedReader;
 4 import java.io.IOException;
 5 import java.io.InputStreamReader;
 6 
 7 
 8 public class SinonimosAntonimos 
 9 {
10     public static classDiccionario DicCompleto[] = new classDiccionario[20];
11     
12     public static void main(String[] args) throws IOException 
13     {
14 
15         int i = 0;
16         int cont=-1;
17         int opcion=99;
18         
19         //classDiccionario DicCompleto[] = new classDiccionario[2];
20         
21         InputStreamReader ISR = new InputStreamReader(System.in);
22         BufferedReader bftexto = new BufferedReader(ISR);  
23         
24         do 
25         {
26             System.out.println("Ingrese opcion");
27             System.out.println("--------------");
28             System.out.println("1.- Ingresar palabras");
29             System.out.println("2.- Desplegar palabras");
30             System.out.println("3.- Buscar palabra");
31             System.out.println("0.- Salir");
32             opcion = Integer.parseInt(bftexto.readLine());
33             if (opcion!=0)
34             {
35                 switch (opcion)
36                 {
37                     case 1:cont=fnIngresaPalabras(cont+1);
38                            break;
39                     case 2:prDespliegaPalabras(cont);
40                            break;
41                 }
42             }
43         }
44         while (opcion!=0);
45             
46     }
47     
48     public static int fnIngresaPalabras(int i) throws IOException
49     {
50         String palabra;
51         String sinonimo;
52         String antonimo;
53                 
54         InputStreamReader ISR = new InputStreamReader(System.in);
55         BufferedReader bftexto = new BufferedReader(ISR);      
56         
57         do
58         {
59             System.out.print("Ingrese palabra : ");
60             palabra = bftexto.readLine();
61             if (!palabra.equals("XXX"))
62             {
63                 System.out.print("Ingrese Sinonimo : ");
64                 sinonimo = bftexto.readLine();
65                 System.out.print("Ingrese antonimo : ");
66                 antonimo = bftexto.readLine();
67                 DicCompleto[i] = new classDiccionario(palabra,sinonimo,antonimo);
68                 i++;
69                 if (i>DicCompleto.length-1)
70                 {
71                     System.out.println("No es posible agregar elementos");
72                     palabra = "XXX";
73                 }
74             }
75         }
76         while (!palabra.equals("XXX"));
77         return(i-1);
78     }
79     
80     public static void prDespliegaPalabras(int cont)
81     {
82         int i;
83         for (i=0;i<=cont;i++)
84             System.out.println(DicCompleto[i].getPalabra()+" "+
85                                DicCompleto[i].getSinonimo()+" "+
86                                DicCompleto[i].getAntonimo());
87     }
88 }



domingo, 28 de marzo de 2010

Vehículo llamando a clases - Java

 1 
 2 package clasevehiculos;
 3 
 4 
 5 public class ClaseVehiculos 
 6 {
 7 
 8     public static void main(String[] args) 
 9     {
10       Vehiculos auto = new Vehiculos(4, 4, 6); 
11 
12       if (auto.isEncendido())
13           System.out.println("Auto Encendido");
14       else
15           System.out.println("Auto Apagado");
16       
17       auto.darContacto();
18       
19       if (auto.isEncendido())
20           System.out.println("Auto Encendido");
21       else
22           System.out.println("Auto Apagado");
23       
24       auto.ponerEnMarcha();
25       
26       if (auto.isEnMarcha())
27           System.out.println("Auto en marcha");
28       else
29           System.out.println("Auto detenido");
30       
31       auto.quitarContacto();
32       
33       if (auto.isEncendido())
34           System.out.println("Auto Encendido");
35       else
36           System.out.println("Auto Apagado");
37       
38       auto.detenerMarcha();
39       
40       if (auto.isEnMarcha())
41           System.out.println("Auto en marcha");
42       else
43           System.out.println("Auto detenido");
44       
45       auto.quitarContacto();
46       
47       if (auto.isEncendido())
48           System.out.println("Auto Encendido");
49       else
50           System.out.println("Auto Apagado");
51           
52     }
53 }

Palíndromas Java

 1 
 2 package palindromas;
 3 
 4 import java.io.BufferedReader;
 5 import java.io.IOException;
 6 import java.io.InputStreamReader;
 7 
 8 
 9 public class Palindromas 
10 {
11 
12 
13     public static void main(String[] args) throws IOException 
14     {
15         String texto;
16         int i;
17         int j;
18         boolean esPalindroma = true;
19                 
20         InputStreamReader ISR = new InputStreamReader(System.in);
21         BufferedReader bftexto = new BufferedReader(ISR);
22         
23         texto = bftexto.readLine();
24         
25         j=texto.length()-1;
26         for (i=0;i<texto.length() && j>=i;i++)
27             if (!texto.substring(i,i+1).equals(texto.substring(j,j+1)))
28                 esPalindroma = false;
29             else
30                 j = j - 1;
31         
32         if (esPalindroma)
33             System.out.println("La palabra "+texto+" es palindroma");
34         else
35             System.out.println("La palabra "+texto+" no es palindroma");
36         
37         
38         
39     }
40 }

sábado, 27 de marzo de 2010

Leer Datos java

 1 
 2 package leerdatos;
 3 
 4 import java.io.*;
 5 
 6 public class LeerDatos 
 7 {
 8 
 9     public static void main(String[] args) throws IOException 
10     {
11         String nombres;
12         String apellidos;
13         String Num1;
14         String Num2;
15         int N1;
16         int N2;
17         int N3;
18       
19         InputStreamReader ISR = new InputStreamReader(System.in);
20         BufferedReader texto = new BufferedReader(ISR) ;
21         
22         /*System.out.print("Ingrese nombres ... ");
23         nombres = texto.readLine();
24         System.out.print("Ingrese apellidos ... ");
25         apellidos = texto.readLine();
26         System.out.println(nombres);
27         System.out.println(apellidos); */
28         
29         /*System.out.print("Ingrese primer numero ");
30         Num1 = texto.readLine();
31         System.out.print("Ingrese segundo numero ");
32         Num2 = texto.readLine();*/
33         
34         System.out.print("Ingrese primer numero ");
35         N1 = Integer.parseInt(texto.readLine());
36         System.out.print("Ingrese segundo numero ");
37         N2 = Integer.parseInt(texto.readLine());
38         
39         N3 = N1 + N2;
40         
41         System.out.println("La suma es "+N3);
42         
43         
44       }
45 }

Hola Mundo Java

 1 
 2 package holamundo;
 3 
 4 import java.util.*;
 5 
 6 public class HolaMundo {
 7     
 8     
 9     public static void main(String[] args) {
10             System.out.print("Hola mundo ");
17         
18     }
19 }

viernes, 26 de marzo de 2010

Arreglos - llenar automáticamente

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 
 4 int main(){
 5      printf("\n\n");
 6   printf("            -* PROGRAMA DE ARREGLOS *-\n");
 7      printf("              --------------------\n\n\n\n");
 8 int cantidad; 
 9 int cantidadF;
10 int cont=0;
11 printf("Ingrese la cantidad de numeros del arreglo: ");
12 scanf("%d",&cantidad);
13 printf("\n");
14 //el arreglo es del indice de cantidad
15 int arreglo1[cantidad];
16 for(int i=0;i<=cantidad;i++){
17 arreglo1[i]=i;
18 printf("%i",arreglo1[i]);
19 
20 } 
21 printf("\n\n");
22 //En el caso de una matriz (prueba con 3x3) 
23 printf("Ingrese la cantidad de filas del arreglo: "); 
24 scanf("%d",&cantidadF); 
25 printf("Ingrese la cantidad de columnas del arreglo: "); 
26 scanf("%d",&cantidad);
27 printf("\n");
28 //menos uno porque me contará el cero
29 int arreglo2[cantidadF-1][cantidad-1]; 
30 for(int i=0;i<=cantidadF-1;i++){
31 for(int b=0;b<=cantidad-1;b++){
32   cont++;
33 arreglo2[i][b]=cont;
34 printf("%i  ",arreglo2[i][b]);
35 }
36 printf("\n");
37 }
38 printf("\n\n");
39 
40 system("PAUSE");
41 }