Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

okay I really don\'t know what i a doing wrong this is the assignment \"The clas

ID: 3729292 • Letter: O

Question

okay I really don't know what i a doing wrong this is the assignment "The class RoachPopulation 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 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 a specific number of roaches. Breed, spray and print the roach count. Repeat three more times.

So this is what I got so far and i'm not sure what else it needs:

public class RoachPopulation {

private int numRoaches;

private int intialSize;

public RoachPopulation( int size)

{

numRoaches = size;

}

public void breed()

{

numRoaches = numRoaches * 2;

}

public void spray(double raid)

{

double exterminate = numRoaches * 0.10;

int roachexterminate =(int)exterminate;

numRoaches = numRoaches - roachexterminate;

}

public int getRoaches()

{

return numRoaches;

}

public double getbreed()

{

return numRoaches;

}

public double getspray()

{

return numRoaches;

}

}

but when I test it . its not coming out right. so here is the test method:

import java.util.Scanner;

public class TestRoachPopulation {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.println("Enter the number of roaches in the population: ");

int num = input.nextInt();

RoachPopulation r1 = new RoachPopulation(num);

r1.breed();

r1.spray(0.1);

RoachPopulation r2 = new RoachPopulation(num);

r1.breed();

r1.spray(0.1);

RoachPopulation r3 = new RoachPopulation(num);

r1.breed();

r1.spray(0.1);

for(int i = 1;i<4;i++)

{

System.out.println("After breeding and spraying "+ i +" times the roach count is: "+r1.getRoaches());

  

}

}

}

Explanation / Answer

OUTPUT:

Enter the number of roaches in the population:
1000
After breeding and spraying 1 times the roach count is: 1800
After breeding and spraying 2 times the roach count is: 3240
After breeding and spraying 3 times the roach count is: 5832

//The reason is, you are not using arrays, so it wont be possible to use for loop to print all of them. And you have created three instance variable r1, r2, and r3. But you haven't used r2 and r3 at all, I have commented them coz they are doing nothing.