Hi Guys,
I am trying to write a program in which the user has to enter a list of schools names with an ID according to the school.
So far all is working fine and the data inputed is being written to a Vector:
My Problem is how am i going to validate data in a Vector to verify that the user didn't enter the same ID for two different schools?
----------- MY CODE ---------------
//Ask user to enter School id
System.out.print("Enter School ID: ");
SchoolId = Keyboard.readInt();
boolean Check = schools.contains(SchoolId);
//if the schools id entered is already in vector dispaly user to re-enter the ID
if (Check == true)
{
do
{
System.out.print("School ID already entered ");
SchoolId = Keyboard.readInt();
}
while (Check == true);
}
// add school Id to the vector
schools.add(new Integer (SchoolId));
------------------- PROBLEM ------------------
Since the Boolean check is not being inputed in the loop the Boolean check is remaining obviously with his initial value (this creating an infinite loop when a double entry in inputed)
I if i put the Boolean statement in the DO brackets the While will give me an error that the Variable Check is not being found since it will be used locally in the DO brackets
I am trying to write a program in which the user has to enter a list of schools names with an ID according to the school.
So far all is working fine and the data inputed is being written to a Vector:
My Problem is how am i going to validate data in a Vector to verify that the user didn't enter the same ID for two different schools?
----------- MY CODE ---------------
//Ask user to enter School id
System.out.print("Enter School ID: ");
SchoolId = Keyboard.readInt();
boolean Check = schools.contains(SchoolId);
//if the schools id entered is already in vector dispaly user to re-enter the ID
if (Check == true)
{
do
{
System.out.print("School ID already entered ");
SchoolId = Keyboard.readInt();
}
while (Check == true);
}
// add school Id to the vector
schools.add(new Integer (SchoolId));
------------------- PROBLEM ------------------
Since the Boolean check is not being inputed in the loop the Boolean check is remaining obviously with his initial value (this creating an infinite loop when a double entry in inputed)
I if i put the Boolean statement in the DO brackets the While will give me an error that the Variable Check is not being found since it will be used locally in the DO brackets