NOTE The completed code must pass in the following compiler

NOTE: The completed code must pass in the following compiler. Please make absolutely sure it does before posting: http://codecheck.it/codecheck/files?repo=bj4fp&problem=ch03/c03_exp_3_13

PLEASE also make sure of the following:
-Post this as text, not as an image.
-Do not make alterations to the original code, such as removing/changing parameters, class and variable names etc.
-Post the passing output, as evidence this code was accepted and passed.

~

Implement a class RoachPopulation that simulates the growth of a roach population. The constructor takes the size of the initial roach population. The breed method simulates a period in which the roaches breed, which doubles their population. The spray method simulates spraying with insecticide, which reduces the population by 10%. The getRoaches method returns the current number of roaches. A program called RoachSimulation simulates a population that starts out with 10 roaches. Breed, spray, and print the roach count. Repeat three more times.

Use the following class as your main class:

You need to supply the following class in your solution:

Complete the following file:

RoachPopulation.java

Solution

RoachPopulation.java

import java.io.*;
import java.util.*;
public class RoachPopulation{
   double size;

    RoachPopulation(double size){
  
       this.size = size;
   }
   public void breed(){
   
       size = size*2;
   }
   public void spray(){
    double temp = size;
    temp = (temp * 10)/100;
       size = size-temp;
          int round = (int)size;
          size = round;
   }
   public double getRoaches(){
       return size;
   }

   public static void main(String[] args)
   {
      RoachPopulation population = new RoachPopulation(10);
  
      population.breed();
      population.spray();
      System.out.println(population.getRoaches());
      System.out.println(\"roaches\");
      population.breed();
      population.spray();
      System.out.println(population.getRoaches());
      System.out.println(\"roaches\");
      population.breed();
      population.spray();
      System.out.println(population.getRoaches());
      System.out.println(\"roaches\");
      population.breed();
      population.spray();
      System.out.println(population.getRoaches());
      System.out.println(\"roaches\");
   }
}

Output :
18 roaches
32 roaches
57 roaches
102 roaches

NOTE: The completed code must pass in the following compiler. Please make absolutely sure it does before posting: http://codecheck.it/codecheck/files?repo=bj4fp
NOTE: The completed code must pass in the following compiler. Please make absolutely sure it does before posting: http://codecheck.it/codecheck/files?repo=bj4fp

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site