我需要帮助调试我的程序ChangeMaker。
public class ChangeMaker {
/**
* Constructor for objects of class ChangeMaker
*/
public static void main ( String[] args ) {
for(int x = 1; x < coins; x++) {
int coin = Integer.parseInt(args[x + 1]);
for (int i = 1; i <= quantity; i++) {
Tuple tuple = table[x][i];
int amount = i;
int leftover = amount % coin;
int coinTotal= (int)Math.floor(amount / coin);
if (leftover == 0) {
tuple.setElement(x, coinTotal);
int bestRow = optimalCheck(table, tuple, x, i);
Tuple bestTuple = table[bestRow][i];
tuple.clone(bestTuple);
} else if (leftover != 0 && amount < coin) {
tuple.clone(table[x - 1][i]);
} else if (leftover != 0 && amount > coin) {
tuple.setElement(x, coinTotal);
Tuple leftoverTuple = table[x][leftover];
tuple.add(leftoverTuple);
int bestRow = optimalCheck(table, tuple, x, i);
Tuple bestTuple = table[bestRow][i];
tuple.clone(bestTuple);
}
}
}
每次我尝试调用.clone()方法时,都会出现错误,说java.lang.Object.clone方法不适用(实际和形式参数列表的长度不同)。方法Tuple.clone()不适用。但是,当我注释掉克隆方法时,每个其他方法都可以工作,例如.add()和.setElement()。
这是克隆方法:
public class Tuple
{
private int[] tupleArray;
private int tupleLength;
public Tuple clone () {
Tuple copy = new Tuple(this.tupleLength);
for(int i=0; i<this.tupleLength; i++) {
copy.tupleArray[i]=this.getElement(i);
}
return copy;
}