in java code: Simulate a forest fire. Complete the ForestFireSimulation class by implementing the nextStep() method that will perform the next step in the simulation. At each step, the fuel should be updated. This is done by decrementing the available fuel for a tree by 1. If there is no more fuel available, then the tree should be replaced with ash. Next, trees that are on fire can spread a spark to neighboring trees with a probability of spreadProb. Trees that have a spark should then be turned into a fire in the same step. The final action that needs to be completed in a step is setting new fires. Any tree can be ignited by lightning with a probability of lightningStrikeProb. getForestDensity, getSizeofFire and getFuelLevel should also be implemented in a reasonable fashion. import java.util.Random; public class ForestFireSimulation {    public static final char TREE = '8';    public static final char SPARK = '.';    public static final char FIRE = '*';    public static final char ASH = '^';       public static void main(String[] args) {        ForestFireSimulation ffSimulation = new ForestFireSimulation(15, .45, .01, .4);               for(int i = 0; i < 100; i++) {            ffSimulation.nextStep();            ffSimulation.printForest();            System.out.printf("Forest Density: %.2f\n", ffSimulation.getForestDensity());            System.out.printf("Fuel: %d\n", ffSimulation.getFuelLevel());            System.out.printf("Fire Size: %.2f\n", ffSimulation.getSizeOfFire());            System.out.println("--------------------------------\n");        }    }       char[][] forest;    int[][] fuel;    double lightningStrikeProb;    double spreadProb;    Random r;       public ForestFireSimulation(int N, double forestDensity, double lightningStrikeProb, double spreadProb) {        forest = new char[N][N];        fuel = new int[N][N];        this.lightningStrikeProb = lightningStrikeProb;        this.spreadProb = spreadProb;        r = new Random();               for(int i = 0; i < N; i++) {            for(int j = 0; j < N; j++) {                if(r.nextDouble() < forestDensity) {                    forest[i][j] = TREE;                    fuel[i][j] = r.nextInt(5) + 1;                } else {                    forest[i][j] = ' ';                    fuel[i][j] = 0;                }                           }        }               }       public void printForest() {        System.out.print(" ");        for(int i = 0; i < forest.length; i++) {System.out.print("--");}        System.out.println();        for(int i = 0; i < forest.length; i++) {            System.out.print("|");            for(int j = 0; j < forest[i].length; j++) {                System.out.print(forest[i][j] + " ");            }            System.out.println("|");        }        System.out.print(" ");        for(int i = 0; i < forest.length; i++) {System.out.print("--");}        System.out.println();           }    // help to implement this method    public void nextStep() {               // Update fuel             // Spread sparks                             // Change sparks to fire                     // New fires    }    public double getForestDensity() {               return 0;    }       public double getSizeOfFire() {        return 0;    }       public int getFuelLevel() {        return 0;    }    }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

in java code:

Simulate a forest fire. Complete the ForestFireSimulation class by implementing the nextStep() method that will perform the next step in the simulation. At each step, the fuel should be updated. This is done by decrementing the available fuel for a tree by 1. If there is no more fuel available, then the tree should be replaced with ash. Next, trees that are on fire can spread a spark to neighboring trees with a probability of spreadProb. Trees that have a spark should then be turned into a fire in the same step. The final action that needs to be completed in a step is setting new fires. Any tree can be ignited by lightning with a probability of lightningStrikeProb. getForestDensity, getSizeofFire and getFuelLevel should also be implemented in a reasonable fashion.

import java.util.Random;

public class ForestFireSimulation {

   public static final char TREE = '8';
   public static final char SPARK = '.';
   public static final char FIRE = '*';
   public static final char ASH = '^';
  
   public static void main(String[] args) {

       ForestFireSimulation ffSimulation = new ForestFireSimulation(15, .45, .01, .4);
      
       for(int i = 0; i < 100; i++) {
           ffSimulation.nextStep();
           ffSimulation.printForest();
           System.out.printf("Forest Density: %.2f\n", ffSimulation.getForestDensity());
           System.out.printf("Fuel: %d\n", ffSimulation.getFuelLevel());
           System.out.printf("Fire Size: %.2f\n", ffSimulation.getSizeOfFire());
           System.out.println("--------------------------------\n");
       }

   }
  
   char[][] forest;
   int[][] fuel;
   double lightningStrikeProb;
   double spreadProb;
   Random r;
  
   public ForestFireSimulation(int N, double forestDensity, double lightningStrikeProb, double spreadProb) {
       forest = new char[N][N];
       fuel = new int[N][N];
       this.lightningStrikeProb = lightningStrikeProb;
       this.spreadProb = spreadProb;
       r = new Random();
      
       for(int i = 0; i < N; i++) {
           for(int j = 0; j < N; j++) {
               if(r.nextDouble() < forestDensity) {
                   forest[i][j] = TREE;
                   fuel[i][j] = r.nextInt(5) + 1;
               } else {
                   forest[i][j] = ' ';
                   fuel[i][j] = 0;
               }
              
           }
       }
          
   }
  
   public void printForest() {
       System.out.print(" ");
       for(int i = 0; i < forest.length; i++) {System.out.print("--");}
       System.out.println();
       for(int i = 0; i < forest.length; i++) {
           System.out.print("|");
           for(int j = 0; j < forest[i].length; j++) {
               System.out.print(forest[i][j] + " ");
           }
           System.out.println("|");
       }
       System.out.print(" ");
       for(int i = 0; i < forest.length; i++) {System.out.print("--");}
       System.out.println();
      
   }
  

// help to implement this method
   public void nextStep() {
      
       // Update fuel  
  
       // Spread sparks      

              
       // Change sparks to fire      

      
       // New fires


   }


   public double getForestDensity() {

      
       return 0;
   }
  
   public double getSizeOfFire() {

       return 0;
   }
  
   public int getFuelLevel() {

       return 0;
   }
  
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY