944,129 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 1194
  • Java RSS
Nov 7th, 2009
0

Bacteria Growth

Expand Post »
Having trouble with this one:

The formula y = nekt can be used for estimating growth where

n is the initial amount
k is a constant
t is the time
y is the final amount

This formula will be used for estimating the bacteria growth in a lab experiment. The output should look similar to:

Enter intial bacteria amount:
5.0
Enter a constant value for k:
0.8

Time(hours) Bacteria

1 11.13
2 24.77
3 55.12
4 122.66
5 272.99
6 607.55
7 1352.13
8 3009.23


In the class Mymath , write two different methods:

a. Prompts the user initial bacteria and the constant k in the method.

b. Get the user initial bacteria and the constant k from the main method.

Write a main method to test the two methods above.

My coding:
java Syntax (Toggle Plain Text)
  1. import java.util.Scanner;
  2. public class bacteriagrowth
  3. {
  4. public static void main(String []args)
  5. {
  6. Scanner input = new Scanner (System.in);
  7. double n;
  8. System.out.println("Enter initial bacteria amount: ");
  9. n = input.nextDouble();
  10. double k;
  11. System.out.println("Enter a constant value for k: ");
  12. k = input.nextDouble();
  13. double t = 1;
  14. double y = 0;
  15. while (t<=8)
  16. {
  17. y = Math.pow(n*Math.E, (k*t));
  18. t = t +1;
  19. }
  20. System.out.printf("time" + t, y);
  21.  
  22. }
  23.  
  24. }
Last edited by peter_budo; Nov 7th, 2009 at 4:01 pm. Reason: Please do not use Code Snipets for asking questions. Use Forum Thread option.
Similar Threads
Reputation Points: 9
Solved Threads: 0
Newbie Poster
kulrik is offline Offline
15 posts
since Oct 2009
Nov 8th, 2009
0
Re: Bacteria Growth
Okay? And your question is?
Last edited by masijade; Nov 8th, 2009 at 3:15 am.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Nov 8th, 2009
0
Re: Bacteria Growth
i dont know what im doing wrong. You think you can help me?
Reputation Points: 9
Solved Threads: 0
Newbie Poster
kulrik is offline Offline
15 posts
since Oct 2009
Nov 8th, 2009
0
Re: Bacteria Growth
Click to Expand / Collapse  Quote originally posted by kulrik ...
i dont know what im doing wrong. You think you can help me?
Are you getting an error message? All you've said is the question, and your code. Is there a problem, if so, what is it?
Reputation Points: 12
Solved Threads: 6
Light Poster
Devoted Hosting is offline Offline
29 posts
since Nov 2009
Nov 8th, 2009
0
Re: Bacteria Growth
im not getting the output my teacher wants.
Reputation Points: 9
Solved Threads: 0
Newbie Poster
kulrik is offline Offline
15 posts
since Oct 2009
Nov 9th, 2009
0
Re: Bacteria Growth
I think the problem here is that you are calculating the formula in the wrong way your calculation is:

Java Syntax (Toggle Plain Text)
  1. y = Math.pow(n*Math.E, (k*t));

what this does is multiply E by n, then raise this product by (k*t). Instead what you want to do to get the correct answer is raise E by the product (k*t) then multiply this answer by n to get the correct number. Be careful of the order in which you apply calculations.
Since this is homework I won't give you the correct code but you should be able to do it by yourself anyway. Let us know if this works.
Reputation Points: 16
Solved Threads: 4
Newbie Poster
shibby is offline Offline
14 posts
since Mar 2009
Nov 9th, 2009
0
Re: Bacteria Growth
thanks alot! i got it now.
Reputation Points: 9
Solved Threads: 0
Newbie Poster
kulrik is offline Offline
15 posts
since Oct 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Reading and writing text - help please
Next Thread in Java Forum Timeline: Help needed in matching algorithm





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC