Hi.
I hope you can help me with debugging this piece of code, cause I'm going crazy. I've only implemented the code needed. 'public Model' is the constructor. I have highlighted where the problem is.
//System.out.println(infectedpercell); Somehow both infectedpercell and healthypercell ends up with the exact same Arraylists.private ArrayList<ArrayList<Integer>> healthypercell = new ArrayList<ArrayList<Integer>>(); private ArrayList<ArrayList<Integer>> curedpercell = new ArrayList<ArrayList<Integer>>(); public Model (){ for (int i = 0; i < rowcol; i++) { ArrayList<Character> chr = new ArrayList<Character>(); ArrayList<Integer> nr = new ArrayList<Integer>(); //ArrayList<ArrayList<Agent>> tempag = new ArrayList<ArrayList<Agent>>(); for (int j = 0; j < rowcol; j++) { chr.add(input); nr.add(0); } infectedpercell.add(nr); curedpercell.add(nr); healthypercell.add(nr); lattices.add(chr); } //System.out.println("hej"); for (int i = 0; i < 5; i++) { System.out.println("hej"); if (infected > 0) { sirsend = 'i'; } else { sirsend = 's'; } agx = (int)(Math.random()*100); agy = (int)(Math.random()*100); agents.add(new Agent(agx,agy,sirsend)); if (infected <= 0) { temp = healthypercell.get(agx).get(agy); temp2 = temp+1; healthypercell.get(agx).set(agy, temp2); } else if (infected > 0) { //System.out.println(infectedpercell); counter += 1; temp = infectedpercell.get(agx).get(agy); temp2 = temp+1; //System.out.println(temp2); infectedpercell.get(agx).set(agy, temp2); //if (counter == 5) } if (infected >= 0) infected -= 1; }
//System.out.println(healthypercell);
}