Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public static int calculateEndPopulation ( final int startPopulation, final int maxPopulation, final double growthRate, final int periods ) { if ( periods = = 0
public static int calculateEndPopulationfinal int startPopulation,
final int maxPopulation, final double growthRate, final int periods
if periods
TODO:
return startPopulation;
else
TODO:
Calculate the end population for the first n periods
The start population for the nth period is the end population for the nth period
int startPopulationForNthPeriod calculateEndPopulationstartPopulation maxPopulation, growthRate, periods ;
Calculate the growth rate for the nth period
double newGrowthRate startPopulationForNthPeriod growthRate doublestartPopulationForNthPeriod maxPopulation;
Return the population for the current period
return int newGrowthRate;
I need help figuring out why the code above doesn't pass the code below:
Hint: make sure all calculations are done with doubles, otherwise there will be rounding errors
@Test
void testCalculatePopulation
Note: Populations are whole numbers
We are using the format:
calculateEndPopulationstartPopulation sustainablePpopulation, growthFactor,
numberOfPeriods
assertEquals Recursion.calculateEndPopulation;
assertEquals Recursion.calculateEndPopulation;
assertEquals Recursion.calculateEndPopulation;
assertEquals Recursion.calculateEndPopulation;
assertEquals Recursion.calculateEndPopulation;
assertEquals Recursion.calculateEndPopulation;
assertEquals Recursion.calculateEndPopulation;
assertEquals Recursion.calculateEndPopulation;
Population slowly approaching
assertEquals Recursion.calculateEndPopulation;
assertEquals Recursion.calculateEndPopulation;
assertEquals Recursion.calculateEndPopulation;
But never quite getting to
assertEquals Recursion.calculateEndPopulation;
assertEquals Recursion.calculateEndPopulation;
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