Hello I am in Intro to Java Programming and I am having problems with assignment. The Homework assignment is called Population.
Population
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%, and will be allowed to multiply for 7 days. The program should use a loop to display the size of the population each day.
Input Validation: Do not accept a number less than two 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 one for the number of days they will multiply.
Here is what I have done so far!
import java.util.scann er; // Needed for the scanner class
/**
This program demonstrates a user controlled loop
*/
public class Population
public static void main(String[] args)
{
int Size,
Days,
increase,
number,
Temp;
String input; // To Hold the user's input
//Create a Scanner object for keyboard input.
Scanner Keyboard = new scanner(System. in);
int startingSize = 0, dailyIncrease = 0, numberOfDays = 0;
int temp = 0;
//accept initial user input here
while (startingSize < 2)
{
System.out.prin t("Please enter a number that is greater than 1 for the population size: ");
startingSize = keyboardInput.n extInt(System.i n);
}
while (dailyIncrease < 0)
{
System.out.prin t("Enter a positive integer for the population size increase: ");
dailyIncrease = keyboardInput.n extInt(System.i n);
}
//do the same while loop for numberOfDays as a positive number > 0
temp = startingSize;
dailyIncrease = dailyIncrease + 1;
for(int i = 0; i < numberOfDays; i++)
{
System.out.prin tln("Day " + i);
System.out.prin tln("Number " + temp);
temp = temp * dailyIncrease;
}
					Population
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%, and will be allowed to multiply for 7 days. The program should use a loop to display the size of the population each day.
Input Validation: Do not accept a number less than two 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 one for the number of days they will multiply.
Here is what I have done so far!
import java.util.scann er; // Needed for the scanner class
/**
This program demonstrates a user controlled loop
*/
public class Population
public static void main(String[] args)
{
int Size,
Days,
increase,
number,
Temp;
String input; // To Hold the user's input
//Create a Scanner object for keyboard input.
Scanner Keyboard = new scanner(System. in);
int startingSize = 0, dailyIncrease = 0, numberOfDays = 0;
int temp = 0;
//accept initial user input here
while (startingSize < 2)
{
System.out.prin t("Please enter a number that is greater than 1 for the population size: ");
startingSize = keyboardInput.n extInt(System.i n);
}
while (dailyIncrease < 0)
{
System.out.prin t("Enter a positive integer for the population size increase: ");
dailyIncrease = keyboardInput.n extInt(System.i n);
}
//do the same while loop for numberOfDays as a positive number > 0
temp = startingSize;
dailyIncrease = dailyIncrease + 1;
for(int i = 0; i < numberOfDays; i++)
{
System.out.prin tln("Day " + i);
System.out.prin tln("Number " + temp);
temp = temp * dailyIncrease;
}
Comment