Bacteria Growth

Thread Solved

Join Date: Oct 2009
Posts: 15
Reputation: kulrik is an unknown quantity at this point 
Solved Threads: 0
kulrik kulrik is offline Offline
Newbie Poster

Bacteria Growth

 
0
  #1
20 Days Ago
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:
  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; 20 Days Ago at 4:01 pm. Reason: Please do not use Code Snipets for asking questions. Use Forum Thread option.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,358
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven
 
0
  #2
20 Days Ago
Okay? And your question is?
Last edited by masijade; 20 Days Ago at 3:15 am.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 15
Reputation: kulrik is an unknown quantity at this point 
Solved Threads: 0
kulrik kulrik is offline Offline
Newbie Poster
 
0
  #3
20 Days Ago
i dont know what im doing wrong. You think you can help me?
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 22
Reputation: Devoted Hosting is an unknown quantity at this point 
Solved Threads: 4
Devoted Hosting Devoted Hosting is offline Offline
Newbie Poster
 
0
  #4
19 Days Ago
Originally Posted by kulrik View Post
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?
Devoted Hosting
High Quality Shared And Reseller Hosting
cPanel, 24/7 support, 99.9% uptime guaranteed
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 15
Reputation: kulrik is an unknown quantity at this point 
Solved Threads: 0
kulrik kulrik is offline Offline
Newbie Poster
 
0
  #5
19 Days Ago
im not getting the output my teacher wants.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 10
Reputation: shibby is an unknown quantity at this point 
Solved Threads: 4
shibby shibby is offline Offline
Newbie Poster
 
0
  #6
19 Days Ago
I think the problem here is that you are calculating the formula in the wrong way your calculation is:

  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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 15
Reputation: kulrik is an unknown quantity at this point 
Solved Threads: 0
kulrik kulrik is offline Offline
Newbie Poster
 
0
  #7
19 Days Ago
thanks alot! i got it now.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC