467,926 Members | 1,829 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,926 developers. It's quick & easy.

Stuck on Population Growth Homework

Hello, my homework for computer class says

" In a biology experiment, Cory finds that a sample of
microorganisms doubles in population every 12 hours. He
wants to know how many hours it will take to reach a
certain microorganism population level if he starts with
1000 organisms each time.
WAM (write a method) to receive an integer N representing a desired
organism population level, and determine how many
hours it will be until the population level reaches N or
more organisms."

I can't seem to figure this out at all, the code I have so far reads as follows:

public static int (int X, int Y) {
int size = X;
int hours = 0;
while (size<=Y) {
size * 2;
}
}
Feb 7 '20 #1
  • viewed: 1685
Share:
1 Reply
Expert 256MB
..to receive an integer N..
The function has to accept only one formal argument.

Expand|Select|Wrap|Line Numbers
  1. public static int (int X, int Y) {
No function name is mentioned.

Expand|Select|Wrap|Line Numbers
  1. while (size<=Y) 
It should not check for equality here. Refer the question:
...level reaches N or more organisms...

Expand|Select|Wrap|Line Numbers
  1. size * 2;
This surely is doing size*2 but isn't updating any value.

See the required changes below:
Expand|Select|Wrap|Line Numbers
  1. public static int fun (int N) {
  2.   int size=1000;
  3.   int hours = 0;
  4.   while (size<N) {
  5.     hours+=12;
  6.     size*=2;
  7.   }
  8.   return hours;
  9. }
  10.  
Feb 7 '20 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.