Hi EveryOne,
I am writing a java application called FireSimulation and a I have a bug which needs to be resolved. I will appreciate your help. The code for the following is below.
GRID>JAVA
package Fire.Simulation.riz;
import java.util.Scanner;
public class Grid extends Cell {
public int probablityTree;
public int probablityFire;
boolean willGenerateTree;
boolean willCatchFire;
public double r;
public Cell[][] Box;
public Grid(int rows,int columns)
{
willGenerateTree = false;
willCatchFire = false;
Box= new Cell[rows][columns];
for(int i=0;i<rows;i++)
{
for(int j=0;j<columns;j++)
{
System.out.println("first for");
Box=new Cell[i][j];
}
System.out.println("Second for");
}
}
public void GenerateGrid() {
}
public void ProbTree()
{
for(int i=0;i<(Box.length-1);i++)
{
for(int j=0;j<(Box[0].length-1);j++)
{
r=Math.random();
if(r>0 && r<=probablityTree)
willGenerateTree=true;
r=Math.random();
if(r>0 && r<=probablityFire)
willCatchFire=true;
if(willGenerateTree)
{
if(willCatchFire)
{
Cell[i][j].setState(2);
}
else
{
Cell[i][j].setState(1);
}
}
else
{
Cell[i][j].setState(0);
}
}
}
}
public static void main(String args[])
{
int row, column;
Scanner scan = new Scanner(System.in);
System.out.println("Please enter the number of rows :");
row=scan.nextInt();
System.out.println("Please enter the number of columns :");
column=scan.nextInt();
Grid g = new Grid(row,column);
g.ProbTree();
}
}
Cell.java
package Fire.Simulation.riz;
public class Cell {
public int State;
public int s;
public Cell()
{
}
public int getState() {
return s;
}
public void setState(int s) {
this.s = s;
}
}
The bug is highlited here,
