嗨有没有办法从NFTLP中的for循环中获取int i以在NFTLPAddBox方法中打印出来,因此它说明在哪辆卡车中添加了哪个盒子,例如在卡车0上添加了盒子1,在卡车0上添加了盒子2箱子3在卡车1等处添加。
public void NFTLP() {
trucks.clear();
trucks.add(new Truck());
System.out.println("");
Stack s = new Stack();
s.setStackWidth(boxes[0].getWidth());
trucks.get(0).addStack(s);
for (int i = 0; i < boxes.length; i++) {
NFTLPAddBox(boxes[i],
trucks.get(trucks.size() - 1).getStack().get(trucks.get(trucks.size() - 1).getStack().size() - 1),
trucks.get(trucks.size() - 1));
}
System.out.println("Trucks used: " + trucks.size());
System.out.println("Stacks used: " + Truck.stacks);
}
public void NFTLPAddBox(Box b, Stack s, Truck t) {
if (t.getBoxNum() < Truck.BOX_LIMIT) {
if (b.getWidth() <= s.getStackWidth() && s.getStackHeight() + b.getHeight() <= Truck.TRUCK_HEIGHT) {
s.addBox(b);
t.boxNum++;
System.out.println("Box added at Truck: " + trucks.indexOf(t) + " Stack: "
+ Integer.toString(trucks.get(trucks.indexOf(t)).getStack().size() - 1));
} else {
Stack s2 = new Stack();
if (t.getCurrentStackWidth() + b.getWidth() <= Truck.TRUCK_WIDTH
&& b.getHeight() <= Truck.TRUCK_HEIGHT) {
s2.addBox(b);
t.addStack(s);
t.boxNum++;
System.out.println("Box added at Truck: " + trucks.indexOf(t) + " Stack: "
+ Integer.toString(trucks.get(trucks.indexOf(t)).getStack().size() - 1));
}