==================2nd class============== please let me know how to fix these...
ID: 3726268 • Letter: #
Question
==================2nd class==============
please let me know how to fix these....I know there are something I need to do with the for loops... please help
Due Date: As noted on Blackboard Concepts: Classes and Objects Point value: 100 points 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. 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 xxx_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 xxx_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 aboveExplanation / Answer
import java.util.*;
class RoachPopulation
{
private int numRoach;
public RoachPopulation()//default constructor
{
numRoach = 0;
}
public RoachPopulation(int numRoach)//argument constructor
{
this.numRoach = numRoach;
}
public int getRoaches()
{
return numRoach;
}
public void setRoaches(int numRoach)
{
this.numRoach = numRoach;
}
public void breed()
{
numRoach = numRoach * 2; // double the population
}
public void spray()
{
numRoach = numRoach - (int)(numRoach*0.1); // decrease the roaches population by 10 %
}
}
class RoachSimulation
{
public static void main (String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the number of roaches in the population : ");
int numRoaches = keyboard.nextInt();
RoachPopulation rp = new RoachPopulation(numRoaches);
System.out.println("Creating the Roach Population ");
System.out.println("The initial size of the population is "+rp.getRoaches());
for(int i=1;i<=4;i++)
{
System.out.println("Breeding and Spraying ");
rp.breed();
rp.spray();
System.out.println("After breeding and spraying "+i+" time the roach count is "+rp.getRoaches());
}
}
}
Output:
Enter the number of roaches in the population :
Creating the Roach Population
The initial size of the population is 25
Breeding and Spraying
After breeding and spraying 1 time the roach count is 45
Breeding and Spraying
After breeding and spraying 2 time the roach count is 81
Breeding and Spraying
After breeding and spraying 3 time the roach count is 146
Breeding and Spraying
After breeding and spraying 4 time the roach count is 263
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.