Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. public class SpeciesQuestion
  2. {
  3. public static void main(String[] args)
  4. {
  5. Species firstSpecies = new Species(), secondSpecies = new Species();
  6.  
  7. System.out.println("------------------------------------------");
  8. System.out.println("INPUT FOR FIRST SPECIES");
  9. System.out.println("------------------------------------------");
  10. firstSpecies.readInput();
  11.  
  12. System.out.println("------------------------------------------");
  13. System.out.println("INPUT FOR SECOND SPECIES");
  14. System.out.println("------------------------------------------");
  15. secondSpecies.readInput();
  16.  
  17. if(firstSpecies.getGrowthRate() == secondSpecies.getGrowthRate())
  18. {
  19. if(firstSpecies.getPopulation() == secondSpecies.getPopulation())
  20. {
  21. System.out.println("The populations will always be equal.");
  22. }
  23. else if(firstSpecies.getPopulation() > secondSpecies.getPopulation())
  24. {
  25. System.out.println("The " + firstSpecies.getName() +
  26. " species will always have a larger population.");
  27. }
  28. else
  29. {
  30. System.out.println("The " + secondSpecies.getName() +
  31. " species will always have a larger population.");
  32. }
  33. }
  34.  
  35. if(firstSpecies.getGrowthRate() > secondSpecies.getGrowthRate())
  36. {
  37. if(firstSpecies.getPopulation() == secondSpecies.getPopulation())
  38. {
  39. System.out.println("It will take 1 year for the population " +
  40. " of the " + firstSpecies.getName() + " species to exceed " +
  41. " the population of the " + secondSpecies.getName() +
  42. " species.");
  43. }
  44. else if(firstSpecies.getPopulation() < secondSpecies.getPopulation())
  45. {
  46. System.out.println("It will take " + getYears(firstSpecies,
  47. secondSpecies) + " years for the " + firstSpecies.getName() +
  48. " population to exceed the " + secondSpecies.getName() +
  49. " population.");
  50. }
  51. else //firstSpecies population > secondSpecies population
  52. {
  53. System.out.println("The " + firstSpecies.getName() +
  54. " species will always have a larger population.");
  55. }
  56. }
  57.  
  58. if(firstSpecies.getGrowthRate() < secondSpecies.getGrowthRate())
  59. {
  60. if(firstSpecies.getPopulation() == secondSpecies.getPopulation())
  61. {
  62. System.out.println("It will take 1 year for the population" +
  63. " of the " + secondSpecies.getName() + " species to exceed" +
  64. " the population of the " + firstSpecies.getName() +
  65. " species.");
  66. }
  67. else if(firstSpecies.getPopulation() > secondSpecies.getPopulation())
  68. {
  69. System.out.println("It will take " + getYears(secondSpecies,
  70. firstSpecies) + " years for the " + secondSpecies.getName() +
  71. " population to exceed the " + firstSpecies.getName() +
  72. " population.");
  73. }
  74. else //first species population < second species population
  75. {
  76. System.out.println("The " + secondSpecies.getName() +
  77. " species will always have a larger population.");
  78. }
  79. }
  80. }
  81.  
  82. public static int getYears(Species smallerSpecies, Species largerSpecies)
  83. {
  84. int i = 1;
  85. boolean quit = false;
  86.  
  87. while(true)
  88. {
  89. if(smallerSpecies.predictPopulation(i) > largerSpecies.predictPopulation(i))
  90. {
  91. break;
  92. }
  93.  
  94. ++i;
  95. }
  96.  
  97. return i;
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement