I'm working on an array of objects in java.
I've done an Add, it works. and I'm having problems in implementing a Delete (from the array).
objects are from class called Student, it has a name and ID as members
my work:
// delete an object
if (count == 0)
System.out.println("Sorry there are no items in the system");
else {
System.out.print("Please enter the ID of Student you'd like to Delete: ");
String searchID = in.nextLine();
for (int i =1 ; i<count; i++) { // first : search for the object
if (searchID.equalsIgnoreCase(Students[i].getID())) {
System.out.print("Are you sure you want do delete "
+ Students[i].getName()+ " from the System? ");
String ans = in.nextLine();
if (ans.equalsIgnoreCase("no")) { break; }
if (ans.equalsIgnoreCase("yes")) {
Students[i] = Students[Students.length-1];
break;
}
} else {
System.out.println("Sorry, you need to type a valid ID to delete it's object.. ");
}
}