In: Computer Science
This is JAVA. Must write a short description of this program, usually a sentence or two will be sufficient. All the classes, methods and data fields should be clearly documented (commented).
Write a program that will predict the size of a population of organisms. The program should ask for the starting number of organisms, their average daily population increase (as a percentage), and the number of days they will multiply. For example, a population might begin with two organisms, have an average daily increase of 50 percent (=0.5), and will be allowed to multiply for seven days. The program should use a loop to display the size of the population for each day.
Input Validation: Do not accept a number less than 2 for the starting size of the population. Do not accept a negative number for average daily population increase. Do not accept a number less than 1 for the number of days they will multiply.
Example Run
Enter the starting number organisms: 2
Enter the daily increase: 0.5
Enter the number of days the organisms will multiply: 7
Day Organisms
-----------------------------
1 2.0
2 3.0
3 4.5
4 6.75
5 10.125
6 15.1875
7 22.78125
import java.util.Scanner;
public class Popultion{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double start;
int days;
double increase;
do{
System.out.println("Enter the
starting number organisms: ");
start=sc.nextDouble();
}while(start<2);
do{
System.out.println("Enter the daily
increase: ");
increase=sc.nextDouble();
}while(increase<=0);
do{
System.out.println("Enter the
number of days the organisms will multiply: ");
days=sc.nextInt();
}while(days<1);
for(int i=0;i<days;i++){
System.out.println(start);
start=start +start*increase;
}
}
}
