我正在做一个小型学校项目,请记住我是一个初学者。我要制作一个小型系统,将健身房的成员人数增加到一个数组中。我需要确保人们不能获得相同的会员号,换句话说,要确保在服务器索引点上不会出现相同的值。
到目前为止,我的方法如下:
public void members(int mNr){
if(arraySize < memberNr.length){
throw new IllegalArgumentException("There are no more spots available");
}
if(memberNr.equals(mNr)){
throw new IllegalArgumentException("The member is already in the system");
}
else{
memberNr[count++] = mNr;
}
}
虽然有构造函数和一些类似这样的属性:
int[] memberNr;
int arraySize;
int count;
public TrainingList(int arraySize){
this.arraySize = arraySize;
this.memberNr = new int[arraySize];
}
如您所见,我尝试使用equals,这似乎不起作用。。但是说实话,我不知道如何使每个值唯一 我希望你们中的一些可以帮助我 非常感谢