I am creating a class to check that the number entered is correct. I know the use of exceptions, but at the moment I can not use them. I get two errors, one of while and one of illegal start os expression and I do not know why this is coming out.
public class miScanner {
private final Scanner scanner;
public miScanner() {
this.scanner = new Scanner(System.in);
}
public boolean leeEntero() {
boolean esDatoValido = false;
int numeroEnteroValido = -1;
do {
if (esDatoValido) {
numeroEnteroValido = this.scanner.nextInt();
esDatoValido = true;
}else{
System.out.println("El dato introducido no es un número entero");
} while(!esDatoValido);
return esDatoValido;
}
public double leeDecimal() {
boolean esDatoValido = false;
double numeroDecimalValido = Double.NaN;
do {
if (esDatoValido) {
numeroDecimalValido = this.scanner.nextDouble();
esDatoValido = true;
}else{
System.out.println("El dato introducido no es un número decimal");
}
} while(!esDatoValido);
return numeroDecimalValido;
}
public boolean leeBooleano() {
boolean esDatoValido = false;
boolean booleanoValido = Boolean.FALSE;
do {
if (booleanoValido) {
booleanoValido = this.scanner.nextBoolean();
esDatoValido = true;
}else{
System.out.println("El dato introducido no es un booleano");
}
} while(!esDatoValido);
return booleanoValido;
}
public String leeString() {
return this.scanner.nextLine();
}
}