I'm trying to create a simple program that will check for any given number (an ID) provided by the user and check this ID with an array of numbers inside my program. If the correct ID is given, it will display "Valid ID" if the ID provided by the user is not found, it will display "Invalid ID"
I'm stuck in the part where to use the exceptions. I'm quite lost there. What I can do with what I know is verify the ID provided by the user and check if it's on my array or not. Then I display the message if it's found or not. The problem is, it's supposed to display the exception if the ID is invalid.
My code is as follows:
class InvalidIDException extends Exception
{
InvalidIDException()
{
super("Invalid ID");
}
}
class CheckID{
static int TheArray[] = {10, 11, 12, 13, 14, 15};
static int count = 0;
public static void CheckNumber (int number){
for (int x = 0; x < 6; x++){
if (number == TheArray[x]){
count = 1;
break;
}
}
if (count == 1)
System.out.println("Valid ID");
else
System.out.println("Invalid ID");
}
public static void main(String[] args){
int number = Integer.parseInt(args[0]);
CheckNumber(number);
}
}
Could you guys help me figure out the rest?