elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


  Mostrar Mensajes
Páginas: 1 2 [3] 4 5
21  Programación / Java / Re: Duda_con condicion if en: 28 Diciembre 2012, 14:58 pm
Sii ya me di cuenta, gracias, mira lo voy hacer con String

Felices Fiestas a tí también.
22  Programación / Java / Duda_con condicion if en: 27 Diciembre 2012, 14:42 pm
Hola buenas tardes.

Estoy haciendo un emulador de cajero con Java y me ha surgido una duda en un condicional if dentro de un método.

Me explico mejor entro por consola un numero, lo transformo a String y calculo la longitud de la String y me da un numero, según el tamaño de la misma.

Efectuo if (cadena == 20) // y no me cumple esta condición.

Adjunto los dos archivos el Main, y el de los metodos.

METODO MAIN
=========

Código:
package cuenta;

public class Cuenta {
    public static String name;
    public static String convert;
    public static long account;  
    

    // METODO MAIN
    public static void main(String[] args) {
      // INSTANCIA DEL CONTRUCTOR DATOS  
      CuentaAcciones datos = new CuentaAcciones(name, account,convert);  
      datos.introducirNombre(name);
      datos.introducirCuenta(account);
}
        
    }

CLASE DE LOS METODOS
================

Código:
package cuenta;

import javax.swing.JOptionPane.*;
import java.awt.Toolkit;
import java.util.InputMismatchException;
import java.util.Scanner;

public class CuentaAcciones {  // CLASE PRINCIPAL

    // ATRIBUTOS DE LA CLASE
    private long cuenta;
    private String convierteNumeroCadena;
    private String nombre;


    // CONSTRUCTOR DE DATOS BANCARIOS
    public CuentaAcciones(String nombre, long cuenta, String convierteNumeroCadena){
        this.nombre = nombre;
        this.cuenta = cuenta;
        this.convierteNumeroCadena = convierteNumeroCadena;
    }
  
// METODOS    
void introducirNombre(String nombre){
    Scanner teclado = new Scanner(System.in); // CAPTURA DEL TECLADO    
// DECLARACION DE VARIABLE TIPO STRING
boolean esCadena = false; // OBLIGA A ENTRAR AL BUCLE WHILE

while (esCadena==false){ // BUCLE WHILE

 // IMPRIME NOTAS ACLARATORIAS PARA EL USUARIO  
 System.out.println("    INSTRUCCIONES DE USO"       );
 System.out.println("-------------------------------");
 System.out.println("_El nombre va sin acentos y sin ");
 System.out.println(" sin excederse de 15 caracteres ");
 System.out.println("-------------------------------\n");
 
 // IMPRIME DATOS BANCARIOS
 System.out.println("=======================" );  
 System.out.println("*** DATOS BANCARIOS ***" );
 System.out.println("=======================" );
 
 // NOMBRE DEL USUARIO
 System.out.print("Introduzca su nombre: ");
 nombre=teclado.next();

 // (MATCHES)INCLUYE LETRAS MAYUSCULAS Y MINUSCULAS Y ESPACIOS EN BLANCO
 // Y LA LONGITUD DE CADENA NO PUEDE SER SUPERIOR A 26 CARACTERES
if (nombre.matches("[[a-z]A-Z]*") && (nombre.length() <= 15)){
  System.out.println("Hola "+nombre);
  esCadena = true; // SALE DEL BUCLE
}
      
else{
    System.err.println("¡Error al introducir el nombre!"); // SALIDA POR CONSOLA
    Toolkit.getDefaultToolkit().beep();  // ESTO GENERA UN BEEP
  esCadena = false; // SE MANTIENE EN EL BUCLE
}

}
    
}
void introducirCuenta(long cuenta){
 boolean esNumero = false;  
while (esNumero==false){
    
try{
    Scanner tecladoCuenta= new Scanner(System.in);
    System.out.println("[ENTIDAD ] [OFICINA] [DIGITOS DE CONTROL] [Nº CUENTA]");
    System.out.println("[4 DIGIT ] [4 DIGIT] [     2 DIGIT      ] [10 DIGIT ]");
    System.out.print("Introduzca su numero de cuenta bancaria: ");
    cuenta=tecladoCuenta.nextLong();
    
        this.convierteNumeroCadena = String.valueOf(cuenta);
        System.out.println(convierteNumeroCadena.length());
        long cadena = convierteNumeroCadena.length();
        
    if (convierteNumeroCadena.length() == 20){ // NO SE PQ NO SE CUMPLE ESTO  
      esNumero = true;
      System.out.println("Su numero de cuenta es: "+this.convierteNumeroCadena);
    }
    else{
      System.err.println("¡Error al introducir el numero de cuneta!"); // SALIDA POR CONSOLA
      Toolkit.getDefaultToolkit().beep();  // ESTO GENERA UN BEEP
      esNumero = false;
    }
}

catch (InputMismatchException e)
{
    System.err.println("¡Error al introducir el numero de cuneta!"); // SALIDA POR CONSOLA
    Toolkit.getDefaultToolkit().beep();  // ESTO GENERA UN BEEP
    esNumero = false;
}
}}}
23  Programación / Scripting / Duda_Python_Juego en: 10 Noviembre 2012, 19:52 pm
Hola chicos/as:

Estoy terminando un juego y solo me falta un detalle por hacer.

Les comento tengo un cuadrado azul que representa a una nave y meteoritos que van saliendo aleatoriamente.

Lo único que me queda es hacer que si la nave coge el espacio del meteorito, me ponga un mensaje en pantalla "Chocastes" y con la misma salga del juego.


Les facilito el código, otra cosa esto lo estoy haciendo en PythonG, se que es antiguo pero ya lo empece con este.



Nota del MOD: Usa el botón "Insertar código"

CÓDIGO FUENTE
===========

# EJERCICIO COMPLETO DEL LIBRO_Introducción a la programación con Python
    _EJERCICIO 149

Andrés Marzal Isabel Gracia
Departamento de Lenguajes y Sistemas Informáticos
Universitat Jaume

------------------------------------------------------------------------------------------------
Código
  1. from modulepythong import *
  2. from math import sin, cos, pi
  3. import random
  4. window_style('The Spaceship Game','white','TODO') # FONDO DE COLOR BLANCO
  5.  
  6.  
  7. # Paisaje
  8. altura_paisaje = 400
  9. anchura_paisaje = 400
  10. window_coordinates(0, 0, anchura_paisaje, altura_paisaje)
  11.  
  12. # Gravedad
  13. g = 0.00001
  14.  
  15. # Nave
  16. tamanyo_nave = 10
  17. x = anchura_paisaje / 2
  18. y = altura_paisaje - 100
  19. vy = 0
  20. impulso_y = 2*g
  21. impulso_x = 0.00001
  22. vx = 0
  23. nave = create_filled_rectangle(x, y, x+tamanyo_nave, y+tamanyo_nave, 'blue')
  24.  
  25. # Plataforma
  26. px = anchura_paisaje / 2
  27. py = 0
  28. vpx = .05
  29. anchura_plataforma = 40
  30. altura_plataforma = 3
  31. plataforma = create_rectangle(px, py,px+anchura_plataforma, py+altura_plataforma, 'red')
  32.  
  33. # Tanque de combustible
  34. color = "green" # combustible lleno
  35. fuel = 1000
  36. consumo = 0.01
  37. create_rectangle(0,altura_paisaje, 10, altura_paisaje-100, 'black')
  38. lleno = create_filled_rectangle(1,altura_paisaje, 9, altura_paisaje-fuel/10, color)
  39. create_text(25, altura_paisaje-8, '0%', 10, 'W')
  40. create_text(30, altura_paisaje-95, '100%', 10, 'W')
  41.  
  42. #---------------#
  43. tamanyo_meteorito = 8
  44. punto1=create_filled_circle(100,400,tamanyo_meteorito,"red","brown")
  45. g_m = 0.00001 #Gravedad del meteorito
  46.  
  47. vy_m = 0
  48.  
  49. y_m = 405
  50.  
  51. cord_x = 100
  52. cord_y = 405
  53.  
  54. #----------------#
  55.  
  56. # Dial de velocidad
  57. create_circle(anchura_paisaje-50, altura_paisaje-50, 50, 'black')
  58. for i in range(0, 360, 10):
  59.  create_line(anchura_paisaje-50 + 40 * sin(i*pi/180), \
  60.  altura_paisaje-50 + 40 * cos(i*pi/180), \
  61.  anchura_paisaje-50 + 50 * sin(i*pi/180), \
  62.  altura_paisaje-50 + 50 * cos(i*pi/180))
  63.  if i % 30 == 0:
  64.    create_text(anchura_paisaje-50 + 30 * sin(i*pi/180), \
  65.    altura_paisaje-50 + 30 * cos(i*pi/180), str(i), 5, 'CENTER')
  66.  
  67.    aguja = create_line(anchura_paisaje-50, altura_paisaje-50, \
  68.    anchura_paisaje-50 + 50 * sin(0*pi/180), \
  69.    altura_paisaje-50 + 50 * cos(0*pi/180), 'blue')
  70.  
  71. # Simulacion
  72. while y > 0 and y < altura_paisaje and x > 0 and x < anchura_paisaje - tamanyo_nave:
  73.  vy -= g
  74.  if keypressed(1) == 'Up' and fuel > 0:
  75.    vy += impulso_y
  76.    fuel -= consumo
  77.    if fuel < 350:
  78.      color = "red" # combustible vaciandose
  79.  
  80.  
  81.  elif keypressed(1) == 'Left' and fuel > 0:
  82.    vx -= impulso_x
  83.    fuel -= consumo
  84.    if fuel < 350:
  85.      color = "red" # combustible vaciandose
  86.  
  87.  
  88.  elif keypressed(1) == 'Right' and fuel > 0:
  89.    vx += impulso_x
  90.    fuel -= consumo
  91.    if fuel < 350:
  92.      color = "red" # combustible vaciandose    
  93.  
  94.  
  95.  vy_m = vy_m-g_m
  96.  y_m+=vy_m
  97.  
  98.  move(punto1,0,vy_m)
  99.  
  100.  
  101.  if y_m <= -2:
  102.    erase(punto1)
  103.    cord_x = random.randrange(0,400)
  104.    punto1 = create_filled_circle(cord_x, cord_y, 8,"red","brown")
  105.    y_m = 405
  106.    vy_m = 0
  107.    g_m = 0.00001
  108.  
  109.  y += vy
  110.  x += vx
  111.  px += vpx
  112.  
  113.  if px <= 0 or px >= anchura_paisaje - anchura_plataforma:
  114.    vpx = -vpx
  115.  move(nave, vx, vy)
  116.  move(plataforma, vpx, 0)
  117.  
  118.  viejo_lleno = lleno
  119.  lleno = create_filled_rectangle(1,altura_paisaje, 9, altura_paisaje-fuel/10, color)
  120.  erase(viejo_lleno)
  121.  vieja_aguja = aguja
  122.  aguja = create_line(anchura_paisaje-50, altura_paisaje-50, \
  123.  anchura_paisaje-50 + 50 * sin(1000*vy*pi/180), \
  124.  altura_paisaje-50 + 50 * cos(1000*vy*pi/180), 'blue')
  125.  erase(vieja_aguja)
  126.  
  127. msg_x = anchura_paisaje/2
  128. msg_y1 = altura_paisaje/2
  129. msg_y2 = altura_paisaje/3
  130.  
  131. if y >= altura_paisaje:
  132.  create_text(msg_x, msg_y1, 'Perdiste', 24, 'CENTER')
  133.  create_text(msg_x, msg_y2, 'Rumbo a las estrellas?', 12, 'CENTER')
  134.  
  135. elif y <= 0 and vy < -0.1:
  136.  create_text(msg_x, msg_y1, 'Perdiste', 24, 'CENTER')
  137.  create_text(msg_x, msg_y2, 'Te has estrellado.', 12, 'CENTER')
  138.  
  139. elif y <= 0 and \
  140. abs((px+anchura_plataforma/2)-(x+tamanyo_nave/2)) >= anchura_plataforma/2:
  141.  create_text(msg_x, msg_y1, 'Perdiste', 24, 'CENTER')
  142.  create_text(msg_x, msg_y2, ' !Que mala puntería!', 12, 'CENTER')
  143.  
  144. elif x <= 0 or x >= anchura_paisaje - tamanyo_nave:
  145.  create_text(msg_x, msg_y1, 'Perdiste', 24, 'CENTER')
  146.  create_text(msg_x, msg_y2, 'Chocaste con la pared.', 12, 'CENTER')
  147.  
  148. else:
  149.  create_text(msg_x, msg_y1, 'Ganaste', 24, 'CENTER')
  150.  create_text(msg_x, msg_y2, ' !Enhorabuena, piloto!', 12, 'CENTER')
  151.  
  152. raw_input() # Espera a que pulses una tecla

------------------------------------------------------------------------------------------------
_Links para descagar el PythonG y la version de python compatible.

http://www.mediafire.com/?kfonzec60va8rjr # PythonG
http://www3.uji.es/~dllorens/downloads/pythong/ # Página oficial de descargas PythonG
-----------------------------------------------------------------------------------------------------

http://www.mediafire.com/?ymay3b3bbm6uen6 # Versión de Python 2.3.2
http://www.python.org/download/releases/2.2.3/ # Página Oficial de Python

Muchas Gracias de antemano a todos
24  Programación / Java / Problema con Java en: 16 Octubre 2012, 00:16 am
EJERCICIO DE REFACTORIZACIÓN EN ECLIPSE.

HOLA CHICOS/AS:

Llevo horas intentando hacer un ejercicio de refactorización y que funcione, pero no hay manera de sacarlo, ¿alguien sabe hacerlo?

URL DEL EJERCICIO:

http://cysonline.wordpress.com/2008/08/15/un-ejercicio-de-refactorizacion-carlos-fontela/

Gracias de antemano


25  Programación / Java / Re: Reconstruir este trozo de código en java en: 15 Octubre 2012, 01:03 am
Ya estuve mirando, casi nada, mi madre.

El tema esta increible,y con tiempo dan ganas de seguir con el, pero tiempo no se si me dará porque tengo examen mañana.

SABRIAS COMO SE HACE LA REFACTORIZACION DE ESTE CODIGO, PARA TENERLO DE EJEMPLO, TE LO AGRADECERIA UN MONTON sapito.

public class Forma {
public static final int CUADRADO = 1;
public static final int CIRCULO = 2;
public static final int TRIANGULO_RECTO = 3;
private int tipoForma;
private double size;
public Forma(int tipoForma, double size) {
this.tipoForma = tipoForma;
this.size = size;
}
// ... other methods ...
public double area() {
switch (tipoForma) {
case CUADRADO: return size*size;
case CIRCULO: return Math.PI*size*size/4.0;
case TRIANGULO_RECTO: return size*size/2.0;
}
return 0;
}}

Un Saludo y muchas gracias por toda tu ayuda.

26  Programación / Java / Re: Reconstruir este trozo de código en java en: 14 Octubre 2012, 22:45 pm
Mira una pregunta Sapito?

si yo quiero realizar una refactorización de este trozo de código:

LA REFACTORIZACION: ES UN TECNICA QUE SE UTILIZA PARA RESTRUCTURAR EL CODIGO PERO SIN MODIFICAR SU RESULTADO, ES UNA REORGANIZACION MAS BIEN.

Partiendo de ahí.

Creo que hay una manera de hacer un refactory en eclipse pero no se como se instala, tu sabrás campeón, esto ahorra mucho tiempo en hacerlo a mano

Un saludo.
27  Programación / Java / Reconstruir este trozo de código en java en: 14 Octubre 2012, 15:50 pm
Hola me gustaría refactorizar y probar con JUnit este trozo de código, alguien sabe.

public class Forma {
public static final int CUADRADO = 1;
public static final int CIRCULO = 2;
public static final int TRIANGULO_RECTO = 3;
private int tipoForma;
private double size;
public Forma(int tipoForma, double size) {
this.tipoForma = tipoForma;
this.size = size;
}
// ... other methods ...
public double area() {
switch (tipoForma) {
case CUADRADO: return size*size;
case CIRCULO: return Math.PI*size*size/4.0;
case TRIANGULO_RECTO: return size*size/2.0;
}
return 0;
}}


LA PRUEBA LA ESTOY HACIENDO EN ECLIPSE
Gracias
28  Programación / Java / Re: Multiplica 2 numeros con java en: 13 Octubre 2012, 21:27 pm
Gracias sapito me ha servido de gran ayuda

Un saludo campeón.
29  Programación / Java / Re: Multiplica 2 numeros con java en: 11 Octubre 2012, 16:08 pm
Gracias Aneraka.

Ahora lo que necesito es testearlo con JUint en los IDE Eclipse o Netbeans, me da igual, si sabes como se hace, aquí estoy

Un saludo campeón
30  Programación / Java / Multiplica 2 numeros con java en: 11 Octubre 2012, 14:15 pm
Hola chicos/cas:

Aguién sabe como se puede multiplicar 2 números en java con entrada por teclado
y luego testearlos con JUnit.


Un saludo y gracias de antemano
Páginas: 1 2 [3] 4 5
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines