Buscara errores.

Iniciado por Meta, 24 Abril 2011, 08:06 AM

0 Miembros y 2 Visitantes están viendo este tema.

Meta

Hola:

No se la causa de estos errores.


Main.java
Código (java) [Seleccionar]
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package mypkg;
import java.util.Scanner;
import java.util.InputMismatchException;

/**
*
* @author Hunter
*/
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner lector = new Scanner(System.in);
        int[] palillos = {7,5,3};
        JuegoPalillos juego;
        String[] jugador = new String[2];
        jugador[0] = "Jugador 1";
        jugador[1] = "Jugador 2";
        int turno = 0;
        int fila;
        int cuantos;
        juego = new JuegoPalillos(palillos);

        do{
            System.out.println(juego);
            System.out.printf(jugador[turno]+". elige fila");
            fila = lector.nextInt();
            System.out.printf(jugador[turno]+". ¿cuántos palillos quieres quitar?");
            cuantos = lector.nextInt();
            if (juego.quitaPalillos(fila.cuantos)){
                turno = (turno + 1) % 2;
            }else{
                System.out.printf("Introduce bien la fila y los palillos");
            }
        }catch (InputMismatchException e){
            System.out.printf("por favor introduce un número.");
            lector.next();
        }cath (Exception exc){
            System.out.printf("Se ha producido algún error " + exc.toString());
        }
    }while (!juego.finDeJuego());
    System.out.println("El ganador ha sido " + jugador[turno]);

}


JuegoPalillos.java
Código (java) [Seleccionar]
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package mypkg;

/**
*
* @author Hunter
*/
public class JuegoPalillos {
    private FilaPalillos[] filas;

    public JuegoPalillos(int[] palillos){
        filas = new FilaPalillos[palillos.length];
        for (int i = 0; i < filas.length; i++){
            filas[i] = new FilaPalillos(palillos[i]);
        }
    }

    public boolean quitaPalillos(int fila, int cuantos){
        if (fila < 0 || fila >= filas.length)
            return false;
        else
            return filas[fila].quitaPalillos(cuantos);
    }

    public boolean finDeJuego(){
        for (int i = 0; i < filas.length; ++i){
            if(filas[i].cuantosPalillos() != 0) return false;
        }
        return true;
    }

    public String toString(){
        String s = "";
        for (int i = 0; i < filas.length; i++){
            s += i + " " + filas[i] + "\n";
        }
        return s;
    }
}




FilaPalillos.java
Código (java) [Seleccionar]
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package mypkg;

/**
*
* @author Hunter
*/
public class FilaPalillos {
    private int numPalillos;

    public FilaPalillos(int tamaño){
        numPalillos = tamaño;
    }

    public boolean quitaPalillos(int cuantos){
        if (cuantos > numPalillos){
            return false;
        }else{
            numPalillos -= cuantos;
            return true;
        }
    }

    public String toString(){
        String s = "";
        for (int i=0; i < numPalillos; i++){
            s += "|";
        }
        return s;
    }

    public void añadePalillos(int cuantos){
        numPalillos += cuantos;
    }

    public int cuantosPalillos(){
        return numPalillos;
    }
}


Quiero solucionar los errores de este programa.
Tutoriales Electrónica y PIC: http://electronica-pic.blogspot.com/

1mpuls0

Qué errores?, indicalos.
a qué conclusión llegaste por la cual se ocasionan los errores?

La verdad no creo que muchos quieran compilar esas clases para revisar los errores.

Saludos.
abc

Edu

Yo lo que hago siempre es ir colocando algun mensaje o algo por parte de codigo, cosa q si no llega a ese mensaje se q el error esta antes, luego vas poniendo el mensaje o lo q sea cada vez antes hasta encontrarte con la linea o bucle q de error y entonces ahi dejas aca el codigo del error en vez de dejar todos esos codigos

Shell Root

A simple vista son errores de sintaxis, por ejemplo:
Main.java
Código (java) [Seleccionar]
        }cath (Exception exc){
            System.out.printf("Se ha producido algún error " + exc.toString());
        }


debería ser,
Código (java) [Seleccionar]
        }catch (Exception exc){
            System.out.printf("Se ha producido algún error " + exc.toString());
        }
Por eso no duermo, por si tras mi ventana hay un cuervo. Cuelgo de hilos sueltos sabiendo que hay veneno en el aire.

Meta

Am, lo comprobaré, si que tienes buena vista.
Tutoriales Electrónica y PIC: http://electronica-pic.blogspot.com/