- You have declared
row
ArrayList<Cell>
type as local to the constructor. Declare it in your class context: which is probably you are wanting. - override the
toString()
method and provide an implementation in theRow
class with proper format you want it to see asString
. You will probably need to overridetoString()
method and provide an implementation for theCell
class too. - For a List of specific element, i prefer to declare the list with the element name as prefix and
list
as suffix: suppose instead ofArrayList<Cell>row
, declare it asArrayList<Cell>cellList
For example:
class Cell {
// your other code
@Override
public void String toString() {
return "shipment: " + shipment + "; cost: " + cost;
}
}
class Row{
ArrayList<Cell> cellList = new ArrayList<Cell>();
public Row(Integer[] warehouse) {
for(int value: warehouse)
cellList.add(new Cell(value, 0));
}
@Override
public void String toString() {
return cellList.toString();
}
}
Edit:
you are assigning the class variable wrongly, constructor_local_var <- class_var
: which should be class_var <-- constructor_local_var
public Cell(int x, int y){
cost = x;
shipment = y;
}