Question
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
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.
Sample output:
Enter the number of roaches in the population
25
Creating the Roach Population
The initial size of the population is 25
Breeding and Spraying
After breeding and spraying 1 times the roach count is 45
Breeding and Spraying
After breeding and spraying 2 times the roach count is 81
Breeding and Spraying
After breeding and spraying 3 times the roach count is 146
Breeding and Spraying
After breeding and spraying 4 times the roach count is 263
Include the following for the RoachPopulation class:
1. The instance variable of the class, RoachPopulation
2. The methods of the class, RoachPopulation
3. Include 2 constructors: No-arg and one that accepts the initial size of the population
4. Add getters and setters for instance variables
5. Include the breed and spray methods
Include the following for the RoachSimulation class:
1. A main method which creates the RoachPopulation object, calls all the required methods and prints the output.
2. A Scanner object must be used.
3. The class should work for all values entered by the user.
4. The output should look like the sample output above.
Please note the following requirements and how the assignment will be graded:
Two classes submitted and named as required: RoachPopulation and RoachSimulation
A comment at the start or the program describing what the program does (5 points)
Coding style: All code must be indented for readability and consist of only one statement per line. Naming conventions followed for variables and methods (5 points)
RoachPopulation class (30 points - Full credit provided only if class works as expected)
o Instance variable (5 points)
o Constructors (5 points)
o Getter (5 points)
o Setter (5 points)
o breed method (5 points)
o spray method (5 points)
RoachSimulation class (45 points - Full credit provided only if class works as expected)
o Scanner object (5 points)
o Prompt to user and getting value (5 points)
o RoachPopulation object created (10 points)
o Loop used to breed, spray and print message (5 points)
o Methods breed and spray called correctly (10 points)
o Output matches sample output in format (10 points) Submitted on time (10 points)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started