0

我想在交互窗格中测试下面的方法,但不知道如何在方法的参数中创建“Bag other”,以便我可以检查此方法是否有效。

public class ArrayBag implements Bag {

 public boolean removeItems(Bag other) {
    if(other == null){
        throw new IllegalArgumentException("other cannot be null"); 
    } 
    if(other.numItems() == 0){
        return false; 
    }
    //make bag into array 
    Object[] otherArr = other.toArray(); 

    //remove all occurences of item 
    int check = 0; 
    for(int i = 0; i < otherArr.length; i++){
        if(remove(otherArr[i])){
            i--; 
            check++; 
        }
    }

    //return value 
    if(check > 0){
        return true; 
    }else {
        return false; 
    }
}
4

0 回答 0