public class SpeciesFirstTry
1:
2: import java.util.Scanner;
3:
4: public class SpeciesFirstTry
5: {
6: public String name;
7: public int population;
8: public double growthRate;
9:
10: public void readInput( )
11: {
12: Scanner keyboard = new Scanner(System.in);
13: System.out.println("What is the species' name?");
14: name = keyboard.nextLine( );
15:
16: System.out.println("What is the population of the species?");
17: population = keyboard.nextInt( );
18:
19: System.out.println("Enter growth rate (% increase per year):");
20: growthRate = keyboard.nextDouble( );
21: }
22:
23: public void writeOutput( )
24: {
25: System.out.println("Name = " + name);
26: System.out.println("Population = " + population);
27: System.out.println("Growth rate = " + growthRate + "%");
28: }
29:
30: public int getPopulationIn10( )
31: {
32: int result = 0;
33: double populationAmount = population;
34: int count = 10;
35:
36: while ((count > 0) && (populationAmount > 0))
37: {
38: populationAmount = populationAmount +
39: (growthRate / 100) * populationAmount;
40: count--;
41: }
42:
43: if (populationAmount > 0)
44: result = (int)populationAmount;
45:
46: return result;
47: }
48: }