bmendezt08 de Marzo del 2010
Preguntaes sobre un juego de quinela de futbol me parece al compilar lo hace correctamente, pero a la hora de introducir los valores no me reconoce la cadena de caracteres....
los valores a introducir son 'X', '1' o '2'
a ver si alguien me puede echar una mano
Mando el programa
/**
* Class that represents a footballPoll of 15 teams
*/
public class FootballPolls { /** ERROR SINTÀCTIC: el nom de la Class FootballPollserr és
* FootballPolls
*/
final int COMBINATIONS=15;
/**
* Combination of 15 chars
*/
public char[] combination; // ERROR SINTÀCTIC: chr[] és char amb "a"
// ERROR SEMÀNTIC: ha de ser una variable tipo public
/**
* Constructor method<br>
* This method creates an instance of the footballPolls class
*/
public FootballPolls() /** ERROR SINTÀCTIC: el nom del constructor ha de ser el mateix
* que de la class
*/
{
setCombination();
}
/**
* Method that prints the winner random combination
*/
public void printCombination(){
for(int i=0;i<=COMBINATIONS;i++){
System.out.println(combination[i]); /** ERROR SINTÀCTIC: a "prin" s\'ha d\'afegir "tln"
*/
}
System.out.println(".");
}
/**
* Method that inicializes the winner random combination
*/
public void setCombination(){
int i;
combination = new char[COMBINATIONS];
for (i=0;i<COMBINATIONS;i++)
{
double num = Math.random()*3;
if (num<1) combination[i]=\'X\'; //ERROR SINTÀCTIC: la "X" va així \'X\'
else if ((num>=1) & (num<2)) combination[i]=\'1\';
else if (num>=2) combination[i]=\'2\';
}
}
/**
* Method that validatess the user combination with the combination of the football poll
* @param The user combination
*/
public void checkCombination(char[] userCombination)
{
boolean full=true;
int i;
i=1;
while((i<COMBINATIONS) && (full)) /** ERROR SEMÀNTIC: el comparar dues expressions
cadascuna ha d\'estar dintre d\'un parèntessis
*/
{
if (userCombination[i]!=combination[i]) full=false;
}
if(!full)System.out.println("Congratulations.");
else if(full){
System.out.println("Bad combination.");
}
System.out.print("The combination was: ");//ERROR SINTÀCTIC: print, s\'ha d\'afegir "ln"
printCombination();
}
/**
* Tests the methods related with all the management functions specified for the application.
*/
public static void main(String args[]) // ERROR SINTÀCTIC: argv va amb "s" en comptes de "v"
{
FootballPolls j = new FootballPolls(); /** ERROR SINTÀCTIC: en instanciar l\'objecte el nom ha de coincidir amb
el nom de la class per tant FootballPollserr és FootballPolls
*/
if (args.length==1 && args.length==15) //ERROR SINTÀCTIC: argv va amb "s" en comptes de "v"
/** ERROR SEMÀNTIC: l\'operador && avalua cada expressió
args.length==1 .... expressió1, la longitud mínima de la cadena de
caracters ha de ser =1
args.length==15....expressió2, la longitud màxima de la cadena de
caracters ha de ser =15
si es compleix, farà el mètode checkCombination sinó demanarà que
es posi un valor ja sigui \'1\', \'X\' o \'2\' */
{
j.checkCombination(args[1].toCharArray()); //ERROR SINTÀCTIC: argv va amb "s" en comptes de "v"
}
else System.out.println("usage: footballPolls <15 chars>");
}
}
los valores a introducir son 'X', '1' o '2'
a ver si alguien me puede echar una mano
Mando el programa
/**
* Class that represents a footballPoll of 15 teams
*/
public class FootballPolls { /** ERROR SINTÀCTIC: el nom de la Class FootballPollserr és
* FootballPolls
*/
final int COMBINATIONS=15;
/**
* Combination of 15 chars
*/
public char[] combination; // ERROR SINTÀCTIC: chr[] és char amb "a"
// ERROR SEMÀNTIC: ha de ser una variable tipo public
/**
* Constructor method<br>
* This method creates an instance of the footballPolls class
*/
public FootballPolls() /** ERROR SINTÀCTIC: el nom del constructor ha de ser el mateix
* que de la class
*/
{
setCombination();
}
/**
* Method that prints the winner random combination
*/
public void printCombination(){
for(int i=0;i<=COMBINATIONS;i++){
System.out.println(combination[i]); /** ERROR SINTÀCTIC: a "prin" s\'ha d\'afegir "tln"
*/
}
System.out.println(".");
}
/**
* Method that inicializes the winner random combination
*/
public void setCombination(){
int i;
combination = new char[COMBINATIONS];
for (i=0;i<COMBINATIONS;i++)
{
double num = Math.random()*3;
if (num<1) combination[i]=\'X\'; //ERROR SINTÀCTIC: la "X" va així \'X\'
else if ((num>=1) & (num<2)) combination[i]=\'1\';
else if (num>=2) combination[i]=\'2\';
}
}
/**
* Method that validatess the user combination with the combination of the football poll
* @param The user combination
*/
public void checkCombination(char[] userCombination)
{
boolean full=true;
int i;
i=1;
while((i<COMBINATIONS) && (full)) /** ERROR SEMÀNTIC: el comparar dues expressions
cadascuna ha d\'estar dintre d\'un parèntessis
*/
{
if (userCombination[i]!=combination[i]) full=false;
}
if(!full)System.out.println("Congratulations.");
else if(full){
System.out.println("Bad combination.");
}
System.out.print("The combination was: ");//ERROR SINTÀCTIC: print, s\'ha d\'afegir "ln"
printCombination();
}
/**
* Tests the methods related with all the management functions specified for the application.
*/
public static void main(String args[]) // ERROR SINTÀCTIC: argv va amb "s" en comptes de "v"
{
FootballPolls j = new FootballPolls(); /** ERROR SINTÀCTIC: en instanciar l\'objecte el nom ha de coincidir amb
el nom de la class per tant FootballPollserr és FootballPolls
*/
if (args.length==1 && args.length==15) //ERROR SINTÀCTIC: argv va amb "s" en comptes de "v"
/** ERROR SEMÀNTIC: l\'operador && avalua cada expressió
args.length==1 .... expressió1, la longitud mínima de la cadena de
caracters ha de ser =1
args.length==15....expressió2, la longitud màxima de la cadena de
caracters ha de ser =15
si es compleix, farà el mètode checkCombination sinó demanarà que
es posi un valor ja sigui \'1\', \'X\' o \'2\' */
{
j.checkCombination(args[1].toCharArray()); //ERROR SINTÀCTIC: argv va amb "s" en comptes de "v"
}
else System.out.println("usage: footballPolls <15 chars>");
}
}
