I am attempting to construct a list of rows which contain cells. The classes row and cell have been defined.
I want to construct the array list and then print it.
My Code:
import java.util.*;
public class findBfs
{
int numWarehouses;
int numCustomers = 4;
ArrayList<Integer[]> warehouses = new ArrayList<Integer[]>();
Integer[] warehouse1 = {3,6,8,2};
Integer[] warehouse2 = {6,1,2,5};
Integer[] warehouse3 = {7,8,3,9};
class Cell {
int cost;
int shipment;
public Cell(int x, int y){
x = cost;
y = shipment;
}
public int getCost(){
return cost;
}
public int getShipment(){
return shipment;
}
public void updateShipment(int newAmount){
shipment = newAmount;
}
}
class Row{
public Row(Integer[] warehouse) {
ArrayList<Cell> row = new ArrayList<Cell>();
for(int value: warehouse) {
row.add(new Cell(value, 0));
}
}
}
ArrayList<Row> tableu = new ArrayList<Row>();
public findBfs()
{
warehouses.add(warehouse1);
warehouses.add(warehouse2);
warehouses.add(warehouse3);
for(Integer[] thisWarehouse : warehouses)
{
tableu.add(new Row(thisWarehouse));
}
}
public void printTableu() {
for(Row thisRow : tableu) {
System.out.println(thisRow);
}
}
}
Currently with the code I have the following gets printed:
findBfs$Row@25ca623f
findBfs$Row@9f8297b
findBfs$Row@36b4f5a
What has happened? :(
rowArrayList<Cell>type as local to the constructor. Declare it in your class context: which is probably you are wanting.toString()method and provide an implementation in theRowclass with proper format you want it to see asString. You will probably need to overridetoString()method and provide an implementation for theCellclass too.listas suffix: suppose instead ofArrayList<Cell>row, declare it asArrayList<Cell>cellListFor example:
Edit:
you are assigning the class variable wrongly,
constructor_local_var <- class_var: which should beclass_var <-- constructor_local_var