I am making a program that can add students into a doubly linked list. The program starts off by prompting the user to enter a unique ID number. I have an if statement that checks to see if the ID is already in use, but that statement is not working properly. Any suggestions on how to fix this are appreciated, thanks!
public void addIt() {
// Declaring variables
String studentID = null;
String studentLast, studentFirst = null;
boolean continueLoop = true;
int idIndex = 0;
// While loop to loop through and ask for the user to enter ID's
while (continueLoop) {
System.out.println("Enter a new ID: ");
studentID = scan.next();
// Storing the user input into a temporary variable
idIndex = id.find(studentID);
// If the index is >=0 that means the ID number is already in use,
// and user is prompted to enter a different ID
if (idIndex > 0) {
System.out
.println("The ID is already in use");
} else {
continueLoop = false;
}
}
// Prompting the user to enter the student's first and last name
System.out.print("Enter in a first name: ");
studentFirst = scan.next();
System.out.println("Enter in a last Name");
studentLast = scan.next();
// Finally inserting the student into the database
insertRecord(studentLast, studentFirst, studentID);
}
Aucun commentaire:
Enregistrer un commentaire