Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need a java program with a specific output. please see pic attached. Define a cl

ID: 3818675 • Letter: N

Question

need a java program with a specific output. please see pic attached.

Define a class whose objects are records on animal species. The class should have

instance variables for the species name, population, and growth rate. The growth

rate is a percentage that can be positive or negative and can exceed 100 percent.

Include a suitable collection of constructors, mutator methods, and accessor

methods. Include a toString method and an equals method. Include a boolean

valued method named endangered that returns true when the growth rate is

negative and returns false otherwise. Write a test program (or programs) that

tests each method in your class definition.

Must create a Species Record class: SpeciesRecord.java

This is what the output needs to be:

Record is: Name: current population 0, growth rate: 0.004 Setting name. Record is now: Name: Unicorn, current population 0, growth. rate: 0.004 Record is Name Rabbit, current population. 0, growth rate 0.004 Record is Name Horse population 3000 growth rate 0.004 current Setting growth rate. Record is now: Name: Horse, current population: 3000 growth rate: 56.704 Record is Name Dodo, current population 0, growth rate 33.504 Setting population. Record is now: Name: Dodo, current population: 2, growth rate 33.505 Record is: Name: German Shepherd current population 550, growth rate 45.006 Getting population of rabbits: 0 Getting growth rate of German Shepherds 45.006 Getting name from first record Unicorn. The Dodo is red The r abbit is e ndangered false Horses and Unicorns are the same: false Making an identical object of German Shepherds Duplicate record is Name German Shepherd current population: 550 growth. rate: 45.004 Duplicate is same as original German Shepherd: true BUILD SUCCESSFUL total time 0 seconds

Explanation / Answer

SpeciesRecord.java

package species;

public class SpeciesRecord {
   private String speciesName="";
   private int population;
   private double growthRate;
  
   public String getSpeciesName() {
       return speciesName;
   }

   public void setSpeciesName(String speciesName) {
       this.speciesName = speciesName;
   }

   public int getPopulation() {
       return population;
   }

   public void setPopulation(int population) {
       this.population = population;
   }

   public double getGrowthRate() {
       return growthRate;
   }

   public void setGrowthRate(double growthRate) {
       this.growthRate = growthRate;
   }

   public boolean endangered() {
       boolean endangered = false;
       if (growthRate < 0)
           endangered= true;
       System.out.println("The "+speciesName+" is endangered: "+endangered);
       return endangered;
   }
   public String toString(){
       return "Name: "+speciesName+", current population: "+population+" ,growth rate: "+growthRate+"%";
   }
   public boolean equals(SpeciesRecord sr){
       boolean sameSpecies = false;
       if(speciesName.equals(sr.getSpeciesName()))
           sameSpecies= true;
       System.out.println(speciesName+ " and "+sr.getSpeciesName() +" are the same: "+sameSpecies);
       return sameSpecies;
      
   }

}

MainTest.java

package species;

import java.util.ArrayList;

public class MainTest {

   public static void main(String[] args) {

       ArrayList<SpeciesRecord> species= new ArrayList<SpeciesRecord>();
       SpeciesRecord unicorn=new SpeciesRecord();
       SpeciesRecord rabbit=new SpeciesRecord();
       SpeciesRecord horse=new SpeciesRecord();
       species.add(unicorn);
       for(int i=0;i<species.size();i++){
           System.out.println("Record is: "+species.get(i));
       }
       species.add(rabbit);
       species.add(horse);
       System.out.println("Setting Name");
       unicorn.setSpeciesName("Unicorn");
       rabbit.setSpeciesName("Rabbit");
       horse.setSpeciesName("Horse");
       horse.setPopulation(3000);
       for(int i=0;i<species.size();i++){
           System.out.println("Record is: "+species.get(i));
       }
       System.out.println("Setting Growth rate");
       unicorn.setGrowthRate(56.70);
       SpeciesRecord dodo = new SpeciesRecord();
       dodo.setSpeciesName("Dodo");
       dodo.setGrowthRate(-33.5);
       species.add(dodo);
       horse.setGrowthRate(56.7);
       System.out.println("Record is now: "+horse.toString());
       System.out.println("Record is: "+dodo.toString());
      
       System.out.println("Setting population.");
       SpeciesRecord germanShepard= new SpeciesRecord();
       germanShepard.setSpeciesName("German Shephard");
       germanShepard.setPopulation(550);
       germanShepard.setGrowthRate(45);
       dodo.setPopulation(2);
      
       species.add(germanShepard);
       System.out.println("Record is now: "+dodo.toString());
       System.out.println("Record is: "+germanShepard.toString());
      
       System.out.println("Getting Population of Rabbit: "+rabbit.getPopulation());
       System.out.println("Getting growth rate of German Shepard: "+germanShepard.getGrowthRate()+"%");
       System.out.println("Getting name from the first record: "+species.get(0).getSpeciesName());
      
       dodo.endangered();
       rabbit.endangered();
       horse.equals(unicorn);
       System.out.println("Making Identical Objects of German Shephard.");
       SpeciesRecord newGermanShephard =germanShepard;
       System.out.println("Duplicate Record is: "+newGermanShephard);
       System.out.println("Duplicate same is same as original German Shephard: "+newGermanShephard.equals(germanShepard));
   }

}