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

What are the names of the methods declared in the Java class definition in Listi

ID: 3711250 • Letter: W

Question

What are the names of the methods declared in the Java class definition in Listing 5.3, A Species Class Definition—First Attempt, in Chapter 5 of your textbook? For each method name, give the syntax for the first line of the method definition and briefly describe what the method does.

Based on the above code, give the syntax necessary to instantiate the class and call a method on that instantiation (object).

Listing 5.3 A Species Class Definition-First Attempt import java.util.Scanner; public class SpeciesFirstiry We will give a better version of this class later in this chapter public String name; public int population; public double growthRate Later in this chapter you will see that the modifier public for instance variables should be replaced with private public void readInput () Scanner keyboardnew Scanner (System.in); System.out.println("What is the species' name?"); name keyboard.nextLine (); System.out.println("What is the population of the " + "species?") population keyboard.nextInt () System.out.println ("Enter growth rate " + "(% increase per year):"); growthRate keyboard.nextDouble(); public void writeOutput () System.out.println("Name"+name) System.out.printin( "Populationpopulation); System . out, print 1 n ("Growth rate- " + growt hRate + "%"); public int getPopulationIn10 () int result 0 double populationAmountpopulation; int count 10 while ((count > 0) && (populationAmount > 0)) populationAmountpopulationAmount + (growthRate / 100) populationAmount; count-- if (populationAmount > 0) result (int)populationAmount return result

Explanation / Answer

Methods Declared in Side Class

public void readInput():

this method reading the data from the user from the console like population , growth rate, species name

public void writeData():

this method display the data to the console

public int getPopulation():

it is calculating the population on growth rate

Method calling

SpeciesFirstCity city = new SpeciesFirstCity (); // instantiate the class

// setting the properties for the object

city.name="TestSpecies";

city.population=1000;

city.growthRate=5.5;

city.getPopulation(); // calling the method on created object

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote