this is a population problem that asks for number of starting organisms, the percent increase per day and the number of days allowed to grow. this program is done and fully compiled but i feel like im missing something. can someone double check my equations. this is the entire code. Thanks much
Code:
//Programmer: David
//CS 75 TTh
//Assignment #4 Programming Challenge "Population"
//Due: 9-29-15
//This program will allow the user to predict the size of
//the population of an organism by using loops. In addition, the results should
//be stored in an output file and printed.
import java.util.Scanner; //needed for the Scanner class
import java.io.*; //needed for the File and IOException
public class Population
{
public static void main (String [] args) throws IOException
{
double numOfOrganisms; //store user input for starting number of organisms
double dailyIncrease; //store user input for percent increase per day
//this needs to be converted to a percent by dividng by 100
double startValue; //store for initial number of organisms and daily increase
double days; //store user input for the number of days organism will multiply
Scanner keyboard = new Scanner (System.in); //create object for user input
//ask the user for starting amount of organisms
System.out.print("Enter the amount of starting organisms: ");
numOfOrganisms = keyboard.nextInt();
//determine if amount of organisms is valid choice using while loop
while (numOfOrganisms < 2)
{
System.out.println("Invalid input for starting organisms.");
System.out.print("Please enter 2 or more starting organisms: ");
numOfOrganisms = keyboard.nextInt();
System.out.print("You entered a total of " + numOfOrganisms + " organisms\n");
}
//ask the user for percent population increase, will convert to percentage later
System.out.print("Enter the average daily percent population increase: ");
dailyIncrease = keyboard.nextDouble();
//determine if daily increase is valid using while loop
while (dailyIncrease <= 0)
{
System.out.println("Invalid input for daily increase.");
System.out.print("Please enter a non-negative number for daily increase: ");
dailyIncrease = keyboard.nextInt();
System.out.println("You entered a total of " + dailyIncrease + " percnet daily increase.");
}
//ask the user number of days
System.out.print("Enter the number days for the population to grow: ");
days = keyboard.nextInt();
//determine if days is valid using while loop
while (days <= 1)
{
System.out.println("Invalid input for days entered.");
System.out.print("Please enter 2 or more for total days: ");
days = keyboard.nextInt();
System.out.println("You entered a total of " + days + " days.");
}
//Open the file and create PrintWriter object
PrintWriter outputFile = new PrintWriter("PopulationList.txt");
//design file header for displaying final results
outputFile.println("Days\t\t Total Population");
outputFile.println("*********************************");
//store result of initial number of organisms multiplied by daily increase
//also divided by 100 to convert to percentage
startValue = (dailyIncrease/100)*(numOfOrganisms);
//use for loop to compute each result based on number of days
for ( int i = 0; i < days; i++)
{
System.out.println(i+1 + "\t\t " + numOfOrganisms);
outputFile.println(i+1 + "\t\t " + numOfOrganisms);
numOfOrganisms = numOfOrganisms + startValue;
}
//Close the file
outputFile.close();
System.out.println("Data written on the file.");
}
}
/*
C:\Users\Matt\Documents\Java>java Population
Enter the amount of starting organisms: 11
Enter the average daily percent population increase: 25
Enter the number days for the population to grow: 10
1 11.0
2 13.75
3 16.5
4 19.25
5 22.0
6 24.75
7 27.5
8 30.25
9 33.0
10 35.75
Data written on the file.
*/
Comment