Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Phase 2 Please download Species.java and CircleOfLife.java. Use CircleOfLife.Java for testing Species.java as you follow these steps: Phase 3 Create a Species constructor that takes

Phase 2 Please download Species.java and CircleOfLife.java. Use CircleOfLife.Java for testing Species.java as you follow these steps:

Phase 3 Create a Species constructor that takes in a String for its name, an int for its population, and an int for its growth rate. Don't let someone initialize a species with a population above 1500 or below 1, or a growth rate outside of the range of 1 to 20 percent. If the population is initialized below 1, set it to 1, and if above 1500, set it to 1500. Similarly for the growth rate.

Phase 4 Return an appropriate String in the toString method that describes the state of a Species object. Example String to return in the toString() method: Name of species: cat Population: 1200 Growth Rate: 12% Once you have created a toString method, you can use it to display a Species object stored in a variable s as follows: System.out.println(s); which is a shortcut for System.out.println(s.toString());

Phase 5 Create two species objects of whatever animal that you wish (do this in CircleOfLife.java).

Phase 6 Complete the code for mergeSpecies(Species other). This is a non-static method (as all of the rest of them are) that takes another species as a parameter. This method adds the populations of the two species, changes the name of the species to the concatenation of the two names, and the growth rate to the maximum of the two growth rates

Phase 7 Complete the code for grow() and populationInXYears(int x) (hint: don't change the value of the population for the populationInXYears method -- simply return what the population will be in X years given the growth rate of that species. EXAMPLE If the species are rabbits and their growth rate is 10%, population is 100, and x is 2, you should see The projected population for the rabbits in 2 years will be 121.

Species.java

public class Species { // Put the instance variable here. // .... // Create a Species constructor that takes in a String for its name, an int for // its population, and an int for its growth rate per year as a percent. // .... // mergeSpecies adds the populations of the two species, changes the name // of the species to the concatenation of the two names, and the growth // rate to the maximum of the two growth rates. public void mergeSpecies(Species other) { // .... System.out.println("mergeSpecies NOT IMPLEMENTED YET"); } public String toString(){ // .... System.out.println("toString NOT IMPLEMENTED YET"); return ""; } // Increases the population according to the growth rate of the species, i.e. // updates the population instance variable by adding to it the growth rate/100 times the current population. public void grow() { // .... System.out.println("grow NOT IMPLEMENTED YET"); } // Returns the population of the species in x years according to its growth rate. public int populationInXYears(int x){ // .... System.out.println("getPoplulationInXYears NOT IMPLEMENTED YET"); return 1; } public static void main(String[] args) { // Put simple code here to test the Species class. It is always a good idea to include // a main method in any class you define. Species a = new Species("Frog", 100, 10); System.out.println(a); a.grow(); System.out.println(a); System.out.println("a.populationInXYears(10) returns " + a.populationInXYears(10)); Species b = new Species("Rabbit", 10, 23); a.mergeSpecies(b); System.out.println("a.mergeSpecies(b) is " + a); } }

Circleoflife.java

public class CircleOfLife { public static void main(String args[]) { // Create a new Species object here, passing in the appropriate arguments // Print out the species' growth rate // Use the species' toString here // Call populationInXYears here // Create a new Species object here, passing in the appropriate arguments // using a very large number for the population (e.g. 100000000) // Print out the species' population to make sure it is set to 1500 // Call populationInXYears here, feel free to hardcode in the int to be passed to the method // Call mergeSpecies here. Test that mergeSpecies is doing what you expected it to } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Finance The Role Of Data Analytics In Manda Due Diligence

Authors: Ps Publishing

1st Edition

B0CR6SKTQG, 979-8873324675

More Books

Students also viewed these Databases questions