Explanation of Solution
Modified definition of the class “SpeciesFirstTry” in Listing 5.3:
The modified definition of the class “SpeciesFirstTry” after assigning a number for each species is given below:
//Import package
import java.util.Scanner;
//Define a class "SpeciesFirstTry"
public class SpeciesFirstTry
{
//Declare a string variable for species name
public String name;
//Declare an int variable for species number
public int number;
//Declare an int variable for population
public int population;
//Declare a double variable for species name
public double growthRate;
//Function definition for "readInput"
public void readInput()
{
//Create scanner object
Scanner keyboard = new Scanner(System.in);
//Read input for species name from user
System.out.println("What is the species' name?");
name = keyboard.nextLine();
//Read input for species number from user
System.out.println("What is the species' number?");
number = keyboard.nextInt();
//Read input for population from user
System.out.println("What is the population of the species?");
population = keyboard.nextInt();
//Read input for growth rate from user
System.out.println("Enter growth rate (% increase per year):");
growthRate = keyboard.nextDouble();
}
//Function definition for "writeOutput"
public void writeOutput()
{
//Display species name
System.out.println("Name = " + name);
//Display species number
System...
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Java: Intro. to Prob. Solv... (Looseleaf)
- I do not get the output to print, for any of the classes class point, class LineSegment, What do I need to do in order to pass the points and get the output you got?arrow_forwardAn obvious continuation is to use random numbers to create namesfor the stars and planets. Instead of creating random strings of characters, names usually follow certain rules. Select a set of real-world names (e.g. from J.R.R. Tolkien’sworld) and invent a set of rules that they follow. Design and implement a methodthat creates new names based on the set of rules and random numbers.arrow_forwardPlease solve it with java and post a screenshot of the code for both classes, do not use Scanner and do not use the date packagearrow_forward
- I need to do this in python, help. 7- create a class that represents a point on the Cartesian plane. Next, create a class that represents a triangle, reusing the previous class by composition. Finally, write a program that receives the coordinates of the triangle's vertices from the user and prints its perimeter.arrow_forwardRedefine the equals method of the class Date (Display 4.13) so that it hasa parameter of type Object and follows the other guidelines we gave for anequals method. (Remember, you should use getClass(), not instanceof.)arrow_forwardCan I get a help with this in Java please? Introduce a new class, called Borrower to the project. Its purpose is to represent the borrower of the CD. It should have two fields surname and libraryId; where the latter is a mix of letters and numbers, and a suitable constructor with parameters for only these two fields in the order specified above as well as appropriate accessor methods.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education