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

 

 


Tema destacado: Guía actualizada para evitar que un ransomware ataque tu empresa


  Mostrar Temas
Páginas: 1 ... 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 [41] 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 ... 66
401  Programación / Java / Par impar en: 15 Febrero 2011, 18:42 pm
Buenas:

Quiero hacer que cuando lea el teclado, detecte cuando un número es par o impar. No me sale bien, por ahora he hecho pruebas como vez abajo.

Código:
Scanner teclado = new Scanner(System.in); // Creamos el objeto teclado.

        if ( int numerador = teclado.nextInt() % 2 == 0)
        {
            System.out.println("El número es par.");
        }

        if (teclado % 2 == 1)
        {
            System.out.println("El número es impar.");
        }

No logro que me funcione bien en los if.

Saludo.
402  Programación / Java / Errores en: 15 Febrero 2011, 06:14 am
Buenas:

Estoy haciendo pruebas del Try y Catch. Se trata de que detecte los errores InputMismatchException por si pongo alguna letra en vez de un número en una división y ArithmeticException por si intento dividir por cero pero no pasa nada.

El código que he hecho hasta ahora es este.

Código
  1. try{
  2.        double resultado;
  3.        Scanner teclado=new Scanner(System.in);
  4.        System.out.println("Introduce un numerador: ");
  5.        double numerador = teclado.nextDouble();
  6.        System.out.println("Introduce un denominador: ");
  7.        double denominador = teclado.nextDouble();
  8.  
  9.        resultado = numerador / denominador;
  10.        System.out.println("El numerador " + numerador + " entre el denominador "
  11.                + denominador + " es: " + resultado);
  12.        }
  13.  
  14.        catch (InputMismatchException e){
  15.            System.out.println("Haz introducido algún carácter. \n");
  16.        }
  17.  
  18.        catch (ArithmeticException d){
  19.            System.out.println("No puedes dividir por cero.\n");
  20.            }
  21.        }

Por si acaso, he puesto estos import.
import java.io.*;
import java.util.*;
import java.lang.Exception;
import java.lang.Error;


;)
403  Programación / Java / Resolver este problema en: 13 Febrero 2011, 08:14 am
Buenas:

Partiendo de este código que lo más probable no esté bien diseñado. Estoy haciendo pruebas solo con for y while. Nada de If else o otra instrucción.

Como resultado quiero que de de esta manera.
Código
  1. E3E3E3E3E3
  2. E3E3E3E3E3
  3. E3E3E3E3E3
  4. E3E3E3E3E3
  5. E3E3E3E3E3
  6. E3E3E3E3E3

por ahora me sale solo de esta otra y se queda ahí.
Código
  1. E3E3E3E3E3
  2.  
  3.  
  4.  
  5.  
  6.  

Código
  1. String igual = "";
  2.        String menos = "-";
  3.        int vueltas = 0;
  4.  
  5.        for (int v = 0; v < 6; v++){
  6.        while (vueltas < 5){
  7.        for (int i= 0; i < 1; i++){
  8.            System.out.print(igual);
  9.                for (int j= 0; j < 1; j++){
  10.                    System.out.print(menos);
  11.            }
  12.        }
  13.            vueltas++; // Incremente a uno en la variable.
  14.        }
  15.        System.out.println(); // Salto de línea.
  16.       }

Saludo.
404  Programación / Bases de Datos / Diseñar una buena base de datos en: 12 Febrero 2011, 04:12 am
Hola:

Quiero diseñar una base de datos con SQL Server Express 2008 R2 (Gratuito). Se trata de una base de datos para un videoclub. Cosa que hay que dejar clara. Lo quiero hacer desde Visual C# Espress 2010, es como si fuera Case Studio, se puede hacer relaciones, el algo que no tengo muy en cuenta.

Citar
- Se alquilan películas en dos formatos, el DVD y el Blu-Ray. Tiene una tabla "Formátos" que dentro de ella puedes agregar si se incluye más formatos como el VHS por poner un ejemplo.
- Tiene una tabla llamada "Clientes", en el se encuentra estos campos.
Código
DNI
Nombre
Apellidos
Dirección
Fecha_Nacimiento
Email
Teléfono1
Teléfono2
Móvil1
Móvil2
Observaciones

- Otra tabla llamada "Películas", en él contiene:
Código
Título
Género
Duración
Copias
Disponibles
Precio
Formato
Año
Actor_principal
Director
Descripción
Notas

- Tabla "Película_que_tiene_el_cliente" (Está relacionado con la tabla "Clientes").
Código
Título
Fecha_de_devolución
Días_de_retraso

- Tabla "Clientes_con_copias_de_estas_películas".

Información:
Tabla "Morosos", campos DNI y nombre.

Tabla "Clientes con deudas", campos DNI, Nombre y Total.

Tabla "Alquiladas", campos código película, Título, Cliente, Devolución.

Tabla "Ingresos", con campor de Concepto, DNI, Cliente, Fecha, Hora, Notas

Complicado de entender y de hacer. ¿Verdad?
Espero que no me falte nada, si tienen ideas antes de hacer un esquema de relaciones aunque sea de gannt o con el CASE Studio, también viene con el Visual C# incluido, no duces en compartirlo por aquí.



Un cordial saludo.
405  Programación / Java / Notas de evaluación Java en: 9 Febrero 2011, 17:06 pm
:)

Quiero hacer en Java, qu eme metí ahora mismo en este mundo, que lea por teclado la nota de un estudiante (número real) y muestre en pantalla si es un estudiante destacado, normal o regular. Un estudiante es destacado si su nota es igual o superior a 8, normal si es igual o superior a 5 y menor a 8, y regular si esta por debajo del 5.

Uso el NetBeans 6.9.1 en español.

http://netbeans.org/downloads/index.html

Si escoges la primera opción JAVA se en españo, a 66 MB es suficiente. Trabajo con ella en el Windows 7 64-bits.
406  Programación / .NET (C#, VB.NET, ASP) / Saber que ejecutable o lenguaje es. en: 9 Febrero 2011, 02:30 am
Hola:

Haciendo un ejemplo tonto cualquiera sea con el VB .net o el C# 2010 Express. Creo un botón con un mensaje. Dentro del Form agrego un label y un botón que al pulsarlo muestre Hola mundo por poner un ejemplo sencillo.

¿Hay alguna forma de examinar con cual lenguaje se ha programado ese ejecutable .exe?

Se que puedo cambiar los textos con un editor hexadecimal, también puedo cambiar la versión y nombre de los botones y versiones del programa, cosas así. No se si habrá programa ya hechos para modificar o entender que se ha hecho con ese .exe o al menos hacer un programa nosotros mismo muy sencillo para detectar abrir un .exe y que sepa de qué lenguaje es, otro ejemplo, poner una imagen en el centro de un form1, cosas así.

¿Es posible?

Saludo.
407  Programación / Java / Cálculos Java, mi primner ejemplo en: 8 Febrero 2011, 17:07 pm
Hola:

Quiero hacer mi primer ejemplo con Java con esta operación:
Código
  1.  int x = 10;
  2.  int prueba = x**4 + x**3 + (1/2.0) * x**2 - x;

Lo he intentado hacer con este código completo en NetBeans 6.9.1.

Código
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package acaymo_01;
  7.  
  8. /**
  9.  *
  10.  * @author Hunter
  11.  */
  12. public class Main {
  13.  
  14.    /**
  15.      * @param args the command line arguments
  16.      */
  17.    public static void main(String[] args) {
  18.        // TODO code application logic here
  19.        int x = 10;
  20.        int prueba = x**4 + x**3 + (1/2.0) * x**2 - x;
  21.  
  22.    }
  23.  
  24. }
  25.  

Me sale este error:
Citar
run:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - possible loss of precision
  required: int
  found:    double
        at acaymo_01.Main.main(Main.java:20)
Java Result: 1
GENERACIÓN CORRECTA (total time: 2 seconds)

¿Cuál es el problema?

Lo que debo hacer es mostrar el resultado en pantalla.

Saludo.
408  Programación / Scripting / Hacer un tetris en: 26 Enero 2011, 00:51 am
Quiero hacer un tetris bajo Linux y python en modo consola.

He estado buscando por google pero son encuentro códigos para hacerlo sólo en modo consola, no modo visual como windows.
http://zetcode.com/wxpython/thetetrisgame/

Código
  1. #!/usr/bin/python
  2.  
  3. # tetris.py
  4.  
  5. import wx
  6. import random
  7.  
  8. class Tetris(wx.Frame):
  9.    def __init__(self, parent, id, title):
  10.        wx.Frame.__init__(self, parent, id, title, size=(180, 380))
  11.  
  12.        self.statusbar = self.CreateStatusBar()
  13.        self.statusbar.SetStatusText('0')
  14.        self.board = Board(self)
  15.        self.board.SetFocus()
  16.        self.board.start()
  17.  
  18.        self.Centre()
  19.        self.Show(True)
  20.  
  21.  
  22. class Board(wx.Panel):
  23.    BoardWidth = 10
  24.    BoardHeight = 22
  25.    Speed = 300
  26.    ID_TIMER = 1
  27.  
  28.    def __init__(self, parent):
  29.        wx.Panel.__init__(self, parent)
  30.  
  31.        self.timer = wx.Timer(self, Board.ID_TIMER)
  32.        self.isWaitingAfterLine = False
  33.        self.curPiece = Shape()
  34.        self.nextPiece = Shape()
  35.        self.curX = 0
  36.        self.curY = 0
  37.        self.numLinesRemoved = 0
  38.        self.board = []
  39.  
  40.        self.isStarted = False
  41.        self.isPaused = False
  42.  
  43.        self.Bind(wx.EVT_PAINT, self.OnPaint)
  44.        self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
  45.        self.Bind(wx.EVT_TIMER, self.OnTimer, id=Board.ID_TIMER)
  46.  
  47.        self.clearBoard()
  48.  
  49.    def shapeAt(self, x, y):
  50.        return self.board[(y * Board.BoardWidth) + x]
  51.  
  52.    def setShapeAt(self, x, y, shape):
  53.        self.board[(y * Board.BoardWidth) + x] = shape
  54.  
  55.    def squareWidth(self):
  56.        return self.GetClientSize().GetWidth() / Board.BoardWidth
  57.  
  58.    def squareHeight(self):
  59.        return self.GetClientSize().GetHeight() / Board.BoardHeight
  60.  
  61.    def start(self):
  62.        if self.isPaused:
  63.            return
  64.  
  65.        self.isStarted = True
  66.        self.isWaitingAfterLine = False
  67.        self.numLinesRemoved = 0
  68.        self.clearBoard()
  69.  
  70.        self.newPiece()
  71.        self.timer.Start(Board.Speed)
  72.  
  73.    def pause(self):
  74.        if not self.isStarted:
  75.            return
  76.  
  77.        self.isPaused = not self.isPaused
  78.        statusbar = self.GetParent().statusbar
  79.  
  80.        if self.isPaused:
  81.            self.timer.Stop()
  82.            statusbar.SetStatusText('paused')
  83.        else:
  84.            self.timer.Start(Board.Speed)
  85.            statusbar.SetStatusText(str(self.numLinesRemoved))
  86.  
  87.        self.Refresh()
  88.  
  89.    def clearBoard(self):
  90.        for i in range(Board.BoardHeight * Board.BoardWidth):
  91.            self.board.append(Tetrominoes.NoShape)
  92.  
  93.    def OnPaint(self, event):
  94.  
  95.        dc = wx.PaintDC(self)        
  96.  
  97.        size = self.GetClientSize()
  98.        boardTop = size.GetHeight() - Board.BoardHeight * self.squareHeight()
  99.  
  100.        for i in range(Board.BoardHeight):
  101.            for j in range(Board.BoardWidth):
  102.                shape = self.shapeAt(j, Board.BoardHeight - i - 1)
  103.                if shape != Tetrominoes.NoShape:
  104.                    self.drawSquare(dc,
  105.                        0 + j * self.squareWidth(),
  106.                        boardTop + i * self.squareHeight(), shape)
  107.  
  108.        if self.curPiece.shape() != Tetrominoes.NoShape:
  109.            for i in range(4):
  110.                x = self.curX + self.curPiece.x(i)
  111.                y = self.curY - self.curPiece.y(i)
  112.                self.drawSquare(dc, 0 + x * self.squareWidth(),
  113.                    boardTop + (Board.BoardHeight - y - 1) * self.squareHeight(),
  114.                    self.curPiece.shape())
  115.  
  116.  
  117.    def OnKeyDown(self, event):
  118.        if not self.isStarted or self.curPiece.shape() == Tetrominoes.NoShape:
  119.            event.Skip()
  120.            return
  121.  
  122.        keycode = event.GetKeyCode()
  123.  
  124.        if keycode == ord('P') or keycode == ord('p'):
  125.            self.pause()
  126.            return
  127.        if self.isPaused:
  128.            return
  129.        elif keycode == wx.WXK_LEFT:
  130.            self.tryMove(self.curPiece, self.curX - 1, self.curY)
  131.        elif keycode == wx.WXK_RIGHT:
  132.            self.tryMove(self.curPiece, self.curX + 1, self.curY)
  133.        elif keycode == wx.WXK_DOWN:
  134.            self.tryMove(self.curPiece.rotatedRight(), self.curX, self.curY)
  135.        elif keycode == wx.WXK_UP:
  136.            self.tryMove(self.curPiece.rotatedLeft(), self.curX, self.curY)
  137.        elif keycode == wx.WXK_SPACE:
  138.            self.dropDown()
  139.        elif keycode == ord('D') or keycode == ord('d'):
  140.            self.oneLineDown()
  141.        else:
  142.            event.Skip()
  143.  
  144.  
  145.    def OnTimer(self, event):
  146.        if event.GetId() == Board.ID_TIMER:
  147.            if self.isWaitingAfterLine:
  148.                self.isWaitingAfterLine = False
  149.                self.newPiece()
  150.            else:
  151.                self.oneLineDown()
  152.        else:
  153.            event.Skip()
  154.  
  155.  
  156.    def dropDown(self):
  157.        newY = self.curY
  158.        while newY > 0:
  159.            if not self.tryMove(self.curPiece, self.curX, newY - 1):
  160.                break
  161.            newY -= 1
  162.  
  163.        self.pieceDropped()
  164.  
  165.    def oneLineDown(self):
  166.        if not self.tryMove(self.curPiece, self.curX, self.curY - 1):
  167.            self.pieceDropped()
  168.  
  169.  
  170.    def pieceDropped(self):
  171.        for i in range(4):
  172.            x = self.curX + self.curPiece.x(i)
  173.            y = self.curY - self.curPiece.y(i)
  174.            self.setShapeAt(x, y, self.curPiece.shape())
  175.  
  176.        self.removeFullLines()
  177.  
  178.        if not self.isWaitingAfterLine:
  179.            self.newPiece()
  180.  
  181.  
  182.    def removeFullLines(self):
  183.        numFullLines = 0
  184.  
  185.        statusbar = self.GetParent().statusbar
  186.  
  187.        rowsToRemove = []
  188.  
  189.        for i in range(Board.BoardHeight):
  190.            n = 0
  191.            for j in range(Board.BoardWidth):
  192.                if not self.shapeAt(j, i) == Tetrominoes.NoShape:
  193.                    n = n + 1
  194.  
  195.            if n == 10:
  196.                rowsToRemove.append(i)
  197.  
  198.        rowsToRemove.reverse()
  199.  
  200.        for m in rowsToRemove:
  201.            for k in range(m, Board.BoardHeight):
  202.                for l in range(Board.BoardWidth):
  203.                        self.setShapeAt(l, k, self.shapeAt(l, k + 1))
  204.  
  205.            numFullLines = numFullLines + len(rowsToRemove)
  206.  
  207.            if numFullLines > 0:
  208.                self.numLinesRemoved = self.numLinesRemoved + numFullLines
  209.                statusbar.SetStatusText(str(self.numLinesRemoved))
  210.                self.isWaitingAfterLine = True
  211.                self.curPiece.setShape(Tetrominoes.NoShape)
  212.                self.Refresh()
  213.  
  214.  
  215.    def newPiece(self):
  216.        self.curPiece = self.nextPiece
  217.        statusbar = self.GetParent().statusbar
  218.        self.nextPiece.setRandomShape()
  219.        self.curX = Board.BoardWidth / 2 + 1
  220.        self.curY = Board.BoardHeight - 1 + self.curPiece.minY()
  221.  
  222.        if not self.tryMove(self.curPiece, self.curX, self.curY):
  223.            self.curPiece.setShape(Tetrominoes.NoShape)
  224.            self.timer.Stop()
  225.            self.isStarted = False
  226.            statusbar.SetStatusText('Game over')
  227.  
  228.    def tryMove(self, newPiece, newX, newY):
  229.        for i in range(4):
  230.            x = newX + newPiece.x(i)
  231.            y = newY - newPiece.y(i)
  232.            if x < 0 or x >= Board.BoardWidth or y < 0 or y >= Board.BoardHeight:
  233.                return False
  234.            if self.shapeAt(x, y) != Tetrominoes.NoShape:
  235.                return False
  236.  
  237.        self.curPiece = newPiece
  238.        self.curX = newX
  239.        self.curY = newY
  240.        self.Refresh()
  241.        return True
  242.  
  243.  
  244.    def drawSquare(self, dc, x, y, shape):
  245.        colors = ['#000000', '#CC6666', '#66CC66', '#6666CC',
  246.                  '#CCCC66', '#CC66CC', '#66CCCC', '#DAAA00']
  247.  
  248.        light = ['#000000', '#F89FAB', '#79FC79', '#7979FC',
  249.                 '#FCFC79', '#FC79FC', '#79FCFC', '#FCC600']
  250.  
  251.        dark = ['#000000', '#803C3B', '#3B803B', '#3B3B80',
  252.                 '#80803B', '#803B80', '#3B8080', '#806200']
  253.  
  254.        pen = wx.Pen(light[shape])
  255.        pen.SetCap(wx.CAP_PROJECTING)
  256.        dc.SetPen(pen)
  257.  
  258.        dc.DrawLine(x, y + self.squareHeight() - 1, x, y)
  259.        dc.DrawLine(x, y, x + self.squareWidth() - 1, y)
  260.  
  261.        darkpen = wx.Pen(dark[shape])
  262.        darkpen.SetCap(wx.CAP_PROJECTING)
  263.        dc.SetPen(darkpen)
  264.  
  265.        dc.DrawLine(x + 1, y + self.squareHeight() - 1,
  266.            x + self.squareWidth() - 1, y + self.squareHeight() - 1)
  267.        dc.DrawLine(x + self.squareWidth() - 1,
  268.        y + self.squareHeight() - 1, x + self.squareWidth() - 1, y + 1)
  269.  
  270.        dc.SetPen(wx.TRANSPARENT_PEN)
  271.        dc.SetBrush(wx.Brush(colors[shape]))
  272.        dc.DrawRectangle(x + 1, y + 1, self.squareWidth() - 2,
  273.        self.squareHeight() - 2)
  274.  
  275.  
  276. class Tetrominoes(object):
  277.    NoShape = 0
  278.    ZShape = 1
  279.    SShape = 2
  280.    LineShape = 3
  281.    TShape = 4
  282.    SquareShape = 5
  283.    LShape = 6
  284.    MirroredLShape = 7
  285.  
  286.  
  287. class Shape(object):
  288.    coordsTable = (
  289.        ((0, 0),     (0, 0),     (0, 0),     (0, 0)),
  290.        ((0, -1),    (0, 0),     (-1, 0),    (-1, 1)),
  291.        ((0, -1),    (0, 0),     (1, 0),     (1, 1)),
  292.        ((0, -1),    (0, 0),     (0, 1),     (0, 2)),
  293.        ((-1, 0),    (0, 0),     (1, 0),     (0, 1)),
  294.        ((0, 0),     (1, 0),     (0, 1),     (1, 1)),
  295.        ((-1, -1),   (0, -1),    (0, 0),     (0, 1)),
  296.        ((1, -1),    (0, -1),    (0, 0),     (0, 1))
  297.    )
  298.  
  299.    def __init__(self):
  300.        self.coords = [[0,0] for i in range(4)]
  301.        self.pieceShape = Tetrominoes.NoShape
  302.  
  303.        self.setShape(Tetrominoes.NoShape)
  304.  
  305.    def shape(self):
  306.        return self.pieceShape
  307.  
  308.    def setShape(self, shape):
  309.        table = Shape.coordsTable[shape]
  310.        for i in range(4):
  311.            for j in range(2):
  312.                self.coords[i][j] = table[i][j]
  313.  
  314.        self.pieceShape = shape
  315.  
  316.    def setRandomShape(self):
  317.        self.setShape(random.randint(1, 7))
  318.  
  319.    def x(self, index):
  320.        return self.coords[index][0]
  321.  
  322.    def y(self, index):
  323.        return self.coords[index][1]
  324.  
  325.    def setX(self, index, x):
  326.        self.coords[index][0] = x
  327.  
  328.    def setY(self, index, y):
  329.        self.coords[index][1] = y
  330.  
  331.    def minX(self):
  332.        m = self.coords[0][0]
  333.        for i in range(4):
  334.            m = min(m, self.coords[i][0])
  335.  
  336.        return m
  337.  
  338.    def maxX(self):
  339.        m = self.coords[0][0]
  340.        for i in range(4):
  341.            m = max(m, self.coords[i][0])
  342.  
  343.        return m
  344.  
  345.    def minY(self):
  346.        m = self.coords[0][1]
  347.        for i in range(4):
  348.            m = min(m, self.coords[i][1])
  349.  
  350.        return m
  351.  
  352.    def maxY(self):
  353.        m = self.coords[0][1]
  354.        for i in range(4):
  355.            m = max(m, self.coords[i][1])
  356.  
  357.        return m
  358.  
  359.    def rotatedLeft(self):
  360.        if self.pieceShape == Tetrominoes.SquareShape:
  361.            return self
  362.  
  363.        result = Shape()
  364.        result.pieceShape = self.pieceShape
  365.        for i in range(4):
  366.            result.setX(i, self.y(i))
  367.            result.setY(i, -self.x(i))
  368.  
  369.        return result
  370.  
  371.    def rotatedRight(self):
  372.        if self.pieceShape == Tetrominoes.SquareShape:
  373.            return self
  374.  
  375.        result = Shape()
  376.        result.pieceShape = self.pieceShape
  377.        for i in range(4):
  378.            result.setX(i, -self.y(i))
  379.            result.setY(i, self.x(i))
  380.  
  381.        return result
  382.  
  383.  
  384. app = wx.App()
  385. Tetris(None, -1, 'Tetris')
  386. app.MainLoop()
  387.  

Si encuentran algo mejor que yo, lo ponen por aquí.
409  Programación / Scripting / [Python] - Calculadora sencilla en: 25 Enero 2011, 15:30 pm
Hola:

Quiero hacer una calculadora sencilla usando números complejos que ustedes deseen. Puede ser este enlace. Desde el rpograma pirncipal en Python 2.x, donde el usuario pueda elegir la operación a realizar y los números complejos con los que trabajar. Se trata tambiñen de crear clases para Python.

Saludo.
410  Informática / Electrónica / Hacer Mayflash VGA Switch Casero en: 24 Enero 2011, 15:43 pm
Quiero hacer un conmutador VGA casero para conectar la PlayStation 3, X-Box 360, Ordenador 1 y Ordenador 2. Quiero al menos saber este modelo en concreto que es de 2 VGA y audio como es por dentro. Si alguien tiene ese modelo de abajo, que lo tenga físicamente. ¿Son capaces de quitarles los tornillos y sacar fotos por dentro? Si es posible, las placa por delante y por detrás.







Ver vídeo:
http://www.youtube.com/watch?v=6mdJMzULGIo

http://www.youtube.com/watch?v=vZHnvHns_Ic
Páginas: 1 ... 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 [41] 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 ... 66
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines