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

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());

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!