-3
\$\begingroup\$

I am trying to create a bank acc multi-time in ArrayList with a random number and every person can create only one ACC I have done this code<

import java.util.ArrayList;
import java.util.Random;
public class BankAcc {
    public String name;
    public int age;
    public int id;

    public BankAcc(String name,int age, int id){
        this.name=name;
        this.age=age;
        this.id=id;

    }
    public String getName(){
        return name;
    }
    public int getAge(){
        return age;
    }
    public int getId() {
        return id;
    }
    Random random =new Random();
    ArrayList<Integer>arrayList=new ArrayList<Integer>();
    while (ArrayList.size()>6){
        int a=random.nextInt(49)+1;
        if (!arrayList.contains(a)){
            arrayList.add(a);
        }
    }
}

This class stores the accounts data

import java.util.ArrayList;
public class storeAcc {
    private ArrayList<BankAcc> BankAcc;
    public storeAcc(){
        BankAcc =new ArrayList<BankAcc>();
    }
    public void addBankAcc(BankAcc acc){
        BankAcc.add(acc);
    }
}
\$\endgroup\$
3
  • \$\begingroup\$ i have done class for ArrayList \$\endgroup\$
    – Mohd MJ
    Nov 22 at 17:07
  • 2
    \$\begingroup\$ Your post has multiple fundamental issues which, to my mind, make it off-topic. 1. Your specification statement is unclear. 2. Your code doesn't even compile, so can't have been tested. 3. Your while loop, even if it had been in a method, makes absolutely no sense. The idea of this forum is that you provide working, tested code and we give feedback on how it can be improved. Your code doesn't meet those criteria. Downvoting. \$\endgroup\$ Nov 23 at 8:39
  • \$\begingroup\$ Look at UUID, though it would indeed be funny if two bank accounts have the same UUID. \$\endgroup\$
    – Joop Eggen
    Nov 23 at 18:17

Browse other questions tagged or ask your own question.