Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: referential integrity in deleting problem!!

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    8
    My Mood
    Cold
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Exclamation 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)
    {
    cList.remove(i);
    return i;
    }
    }

    return -1;

    }

    WHILE THIS IS IN THE RUNNER CLASS;


    case 8:

    //Delete a Client from the DvdShop
    System.out.println("Enter ID of Client you want to delete: ");
    int indexPo = myDvdShop.removeClient(sc.nextInt());

    if(indexPo!= -1)
    {
    //Person exists and his position in array list is retrieved
    System.out.println("Client deleted");
    }
    else
    {
    //Person does not exists
    System.out.println("No matching ID found to delete!! ");
    }

    break;

    thanks verymuch


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default 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.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

Similar Threads

  1. deleting all linked list elements using ADT
    By memo1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 25th, 2011, 02:01 PM
  2. [Help] Problem with Class arrays, adding/editing and deleting
    By Grant_Searle in forum Object Oriented Programming
    Replies: 7
    Last Post: December 16th, 2011, 10:10 AM
  3. Deleting Array Records
    By rainexel in forum Collections and Generics
    Replies: 3
    Last Post: September 26th, 2011, 11:40 AM
  4. Deleting record from database HELP! :(
    By shando1992 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 2nd, 2011, 12:36 AM
  5. renaming/deleting file
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 15
    Last Post: January 15th, 2011, 12:18 AM