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