I am trying to do a primary key so that each member can't hava the same ID and if th same ID is entered an error is give. Can someone please help me cause I can't do it at all.Thank you.

static void addMember(ArrayList<GymUser> UserListIn)
    {


        String tempUserrID;
        String tempID;
        String tempName;
        String tempSurname;
        int tempAge;
        String tempAddress;
        int tempPhone;
        String tempDuration;
        Scanner keyboard = new Scanner(System.in);
        keyboard.useDelimiter("\n");
        System.out.println("Please enter the member's Personal Details");
        System.out.println("-------------------- ");
        System.out.println("Enter the mebership number");
        tempUserrID = keyboard.next();
        System.out.print("Enter the ID no.: ");
        tempID = keyboard.next();
        System.out.print("Enter Name: ");
        tempName = keyboard.next();
        System.out.print("Enter Surname:");
        tempSurname = keyboard.next();
        System.out.print("Enter Address:");
        tempAddress = keyboard.next();
        System.out.print("Enter Age:");
        tempAge = keyboard.nextInt();
        System.out.print("Enter Phone:");
        tempPhone = keyboard.nextInt();
        System.out.print("MemberShip Duration:");
        tempDuration = keyboard.next();
        UserListIn.add(new GymUser(tempUserrID, tempName, tempID, tempSurname, tempAddress, tempPhone, tempAge,tempDuration));
        
       
    }  static void addMember(ArrayList<GymUser> UserListIn)
    {


        String tempUserrID;
        String tempID;
        String tempName;
        String tempSurname;
        int tempAge;
        String tempAddress;
        int tempPhone;
        String tempDuration;
        Scanner keyboard = new Scanner(System.in);
        keyboard.useDelimiter("\n");
        System.out.println("Please enter the member's Personal Details");
        System.out.println("-------------------- ");
        System.out.println("Enter the mebership number");
        tempUserrID = keyboard.next();
        System.out.print("Enter the ID no.: ");
        tempID = keyboard.next();
        System.out.print("Enter Name: ");
        tempName = keyboard.next();
        System.out.print("Enter Surname:");
        tempSurname = keyboard.next();
        System.out.print("Enter Address:");
        tempAddress = keyboard.next();
        System.out.print("Enter Age:");
        tempAge = keyboard.nextInt();
        System.out.print("Enter Phone:");
        tempPhone = keyboard.nextInt();
        System.out.print("MemberShip Duration:");
        tempDuration = keyboard.next();
        UserListIn.add(new GymUser(tempUserrID, tempName, tempID, tempSurname, tempAddress, tempPhone, tempAge,tempDuration));
        
       
    }

inside UserListIn.add u put the validation code which will loop through the database and see whether id has been taken by some one or not if id is found it should give error msg
you can also raise exception in that case

Mainly I don't know if I have to do a loop and how to code it. I am confused.
Can you help me DangerDev pls?
Thanks.

This article has been dead for over six months. Start a new discussion instead.