Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SpeciesQuestion
- {
- public static void main(String[] args)
- {
- Species firstSpecies = new Species(), secondSpecies = new Species();
- System.out.println("------------------------------------------");
- System.out.println("INPUT FOR FIRST SPECIES");
- System.out.println("------------------------------------------");
- firstSpecies.readInput();
- System.out.println("------------------------------------------");
- System.out.println("INPUT FOR SECOND SPECIES");
- System.out.println("------------------------------------------");
- secondSpecies.readInput();
- if(firstSpecies.getGrowthRate() == secondSpecies.getGrowthRate())
- {
- if(firstSpecies.getPopulation() == secondSpecies.getPopulation())
- {
- System.out.println("The populations will always be equal.");
- }
- else if(firstSpecies.getPopulation() > secondSpecies.getPopulation())
- {
- System.out.println("The " + firstSpecies.getName() +
- " species will always have a larger population.");
- }
- else
- {
- System.out.println("The " + secondSpecies.getName() +
- " species will always have a larger population.");
- }
- }
- if(firstSpecies.getGrowthRate() > secondSpecies.getGrowthRate())
- {
- if(firstSpecies.getPopulation() == secondSpecies.getPopulation())
- {
- System.out.println("It will take 1 year for the population " +
- " of the " + firstSpecies.getName() + " species to exceed " +
- " the population of the " + secondSpecies.getName() +
- " species.");
- }
- else if(firstSpecies.getPopulation() < secondSpecies.getPopulation())
- {
- System.out.println("It will take " + getYears(firstSpecies,
- secondSpecies) + " years for the " + firstSpecies.getName() +
- " population to exceed the " + secondSpecies.getName() +
- " population.");
- }
- else //firstSpecies population > secondSpecies population
- {
- System.out.println("The " + firstSpecies.getName() +
- " species will always have a larger population.");
- }
- }
- if(firstSpecies.getGrowthRate() < secondSpecies.getGrowthRate())
- {
- if(firstSpecies.getPopulation() == secondSpecies.getPopulation())
- {
- System.out.println("It will take 1 year for the population" +
- " of the " + secondSpecies.getName() + " species to exceed" +
- " the population of the " + firstSpecies.getName() +
- " species.");
- }
- else if(firstSpecies.getPopulation() > secondSpecies.getPopulation())
- {
- System.out.println("It will take " + getYears(secondSpecies,
- firstSpecies) + " years for the " + secondSpecies.getName() +
- " population to exceed the " + firstSpecies.getName() +
- " population.");
- }
- else //first species population < second species population
- {
- System.out.println("The " + secondSpecies.getName() +
- " species will always have a larger population.");
- }
- }
- }
- public static int getYears(Species smallerSpecies, Species largerSpecies)
- {
- int i = 1;
- boolean quit = false;
- while(true)
- {
- if(smallerSpecies.predictPopulation(i) > largerSpecies.predictPopulation(i))
- {
- break;
- }
- ++i;
- }
- return i;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement