These are my questions:
I'm getting a couple of errors on the line "public static boolean validNumCheck(String num){" - "illegal start of expression", "';' expected", and "')' expected".
How can I give the user 3 tries in total for each number? I believe right now the programme asks the user for 3 numbers and gives them 3 tries in total to get the numbers correct (My explanations suck... read the code to get a better idea of what I mean).
This is my code:
import javax.swing.JOptionPane;
public class Assignment3 {
public static void main (String[] args){
final int MAX_TRIES = 3;
int[] attempts= new int[2];
String[] getNumber= new String [2];
//Ask the user for 3 integers.
while(attempts[0]<MAX_TRIES){
getNumber[0]= JOptionPane.showInputDialog(null,"Please enter an integer between 0-200.");
//Pass the value to validNumChek
validNumCheck (getNumber);
//If it is not a valid number give the user 3 more tries.
if (getNumber== false){
while(attempts[1]<MAX_TRIES){
getNumber[1]= JOptionPane.showInputDialog(null,"Please enter an integer between 0-200.");
attempts[1]++;}
}
attempts[0]++;
}
//Parse the string to an integer and check if it is a valid number.
public static boolean validNumCheck(String num){
int number;
try {
number = Integer.parseInt(num);
return number >= 0 && number <= 200;
}catch(NumberFormatException e){
//If it is not a valid number return false.
return false;
}
}
}