referential integrity in deleting problem!!
hi there, i am currently doing a dvd rental system. I have a client class and a salesperson class(both inherit from a Person class), Dvd class, Loan class, DvdShop class and the Runner class. Now, my problem is that I have to do a method where the user can delete a client from the client list (which is an arraylist named cList) BUT cannot delete the client if he has a a dvd still not returned back. I have already done the delete method but i don't know how to do the part where the program checks if the client id is in a loan. The loans are kept in a LoanList (which is also an array list)
Can you help please??
Here is what I did so far;
THIS IS IN THE DvdShop;
public int removeClient (int IDToSearch)
for(int i=0; i<cList.size(); i++)
Client tmpClient = (Client)cList.get(i);
if(tmpClient.GetId() == IDToSearch)
WHILE THIS IS IN THE RUNNER CLASS;
//Delete a Client from the DvdShop
System.out.println("Enter ID of Client you want to delete: ");
int indexPo = myDvdShop.removeClient(sc.nextInt());
//Person exists and his position in array list is retrieved
//Person does not exists
System.out.println("No matching ID found to delete!! ");
thanks verymuch :)
Re: referential integrity in deleting problem!!
Copeg told you in your other thread to wrap up your code in code tags (as found in my signature), so could you listen to him in the future please, It makes code easier to read.
Anyway, your code isn't hugely relevant on this occasion as your question is more about program logic than Java syntax.
Similarly to how you look for the ID to match up, you simply need to add a check to see if client has an outstanding return. You should have a method somewhat like, boolean isRenting() etc. which you can check before deletion.