Question: A local biologist needs a program to predict population growth. The inputs would be the initial number of organisms, the rate of growth, the number
A local biologist needs a program to predict population growth. The inputs would be the initial number of organisms, the rate of growth, the number of hours it takes to achieve this rate (growth period), and a number of hours during which the population grows. For example, one might start with a population of 500 organisms, a growth rate of 2, and a growth period to achieve this rate of 6 hours. Assuming that none of the organisms die, this would imply that the population would double in size every 6 hours. Thus, after allowing 6 hours of growth, we would have 1000 organisms, and after 12 hours, we would have 2000 organisms. Write a program that takes these inputs and displays a prediction of the total population.
Example Run:
Enter the initial number of organisms: 100
Enter the rate of growth: 2
Enter the growth period: 3
Enter the number of hours the population grows: 12
In 12 hours, there will be 1600 organisms
So the code I have for this problem is written in JAVA on repl.it is:
import java.util.Scanner;
public class Main {
public static void main (String[] args) {
Scanner scanner= new Scanner(System.in);
double initial, rate, hoursToRate, hoursToGrow, total;
initial = scanner.readDouble("Enter the initial number of organisms: ");
rate = scanner.readDouble("Enter the rate of growth (A real number <0): ");
hoursToRate = scanner.readDouble("Enter the number of hours it takes to achieve this rate");
hoursToGrow = scanner.readDouble("Enter the number of hours which the population grows: ");
if(hoursToGrow > hoursToRate)
{
total = initial + initial *(hoursToGrow / hoursToRate);
System.out.println("The predicted result is "+total+
" organisms.");
}
else
{
total = Math.round(initial * (rate *(hoursToGrow / hoursToRate)));
System.out.println("The predicted result is "+total+" organisms.");
}
}
}
i get the following error:
Main.java:7: error: cannot find symbol initial = scanner.readDouble("Enter the initial number of organisms: "); ^ symbol: method readDouble(String) location: variable scanner of type Scanner Main.java:8: error: cannot find symbol rate = scanner.readDouble("Enter the rate of growth (A real number <0): "); ^ symbol: method readDouble(String) location: variable scanner of type Scanner Main.java:9: error: cannot find symbol hoursToRate = scanner.readDouble("Enter the number of hours it takes to achieve this rate"); ^ symbol: method readDouble(String) location: variable scanner of type Scanner Main.java:10: error: cannot find symbol hoursToGrow = scanner.readDouble("Enter the number of hours which the population grows: "); ^ symbol: method readDouble(String) location: variable scanner of type Scanner
can someone help me fix my code?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
