| | |
Bacteria Growth
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 15
Reputation:
Solved Threads: 0
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:
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)
import java.util.Scanner; public class bacteriagrowth { public static void main(String []args) { Scanner input = new Scanner (System.in); double n; System.out.println("Enter initial bacteria amount: "); n = input.nextDouble(); double k; System.out.println("Enter a constant value for k: "); k = input.nextDouble(); double t = 1; double y = 0; while (t<=8) { y = Math.pow(n*Math.E, (k*t)); t = t +1; } System.out.printf("time" + t, y); } }
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.
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
----------------------------------------------
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
•
•
Join Date: Nov 2009
Posts: 22
Reputation:
Solved Threads: 4
0
#4 19 Days Ago
Devoted Hosting
High Quality Shared And Reseller Hosting
cPanel, 24/7 support, 99.9% uptime guaranteed
High Quality Shared And Reseller Hosting
cPanel, 24/7 support, 99.9% uptime guaranteed
•
•
Join Date: Mar 2009
Posts: 10
Reputation:
Solved Threads: 4
0
#6 19 Days Ago
I think the problem here is that you are calculating the formula in the wrong way your calculation is:
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.
Java Syntax (Toggle Plain Text)
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.
![]() |
Similar Threads
- Entry-Level Tech Support + Growth Potential (Tech / IT Consultant Job Offers)
- Project Help: Growth of a Function (Java)
- What spiked your growth? (Promotion and Marketing Plans)
Other Threads in the Java Forum
- Previous Thread: Reading and writing text - help please
- Next Thread: Help needed in matching algorithm
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class client code compile compiler component database developmenthelp eclipse error event fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide image int integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loops mac main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying number online pearl problem program programming project qt recursion scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows working xor






