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: An Introduction to Problem Solving and Programming (8th Edition)
- Help, I making a elevator simulator, I need help in writing code in the Elevator class and it's polymorphism class. I am not sure what to do next. Any help is appreciated. There are 4 types of passengers in the system:Standard: This is the most common type of passenger and has a request percentage of 70%. Standard passengers have no special requirements.VIP: This type of passenger has a request percentage of 10%. VIP passengers are given priority and are more likely to be picked up by express elevators.Freight: This type of passenger has a request percentage of 15%. Freight passengers have large items that need to be transported and are more likely to be picked up by freight elevators.Glass: This type of passenger has a request percentage of 5%. Glass passengers have fragile items that need to be transported and are more likely to be picked up by glass elevators. There are 4 types of elevators in the system:StandardElevator: This is the most common type of elevator and has a request…arrow_forwardConsider writing a program to manage a collection of movies. There are three kinds of movies in the collection: dramas, comedies, and documentaries. The collector would like to keep track of each movie's title, the name of its director, and the year the movie was made. Some operations are to be implemented for all movies, and there will also be special operations for each of the three different kinds of movies. How would you design the class(es) to represent this system of movies? Your design should implement the concept of Overridingarrow_forwardCan a class be a super class and a sub-class at the same time? Give example.arrow_forward
- Answer the following and code in Java Thank youarrow_forwardFor this assignment you are tasked to list out the purposes of the AST and Evaluator classes.arrow_forwardCan you implement the Derived Class Parameterized constructor? A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first. Implement the constructor Dell(String name) of the Derived Class Dell which takes a string, name. We have already implemented the Base Class Laptop with the member function getName() and a parameterized constructor. Input# Laptop name is being passed through the parameterized constructor. Output# getName() method is returing Laptop name. Sample Input# Dell dell = new Dell("Dell Inspiron"); Sample Output# "Dell Inspiron"arrow_forward
- language is c++ sample output included with user input in boldarrow_forwardHelp, I am making a elevator simulation using polymorphism. I am not sure to do now. Any help would be appreciated. My code is at the bottom, that's all I could think off. There are 4 types of passengers in the system:Standard: This is the most common type of passenger and has a request percentage of 70%. Standard passengers have no special requirements.VIP: This type of passenger has a request percentage of 10%. VIP passengers are given priority and are more likely to be picked up by express elevators.Freight: This type of passenger has a request percentage of 15%. Freight passengers have large items that need to be transported and are more likely to be picked up by freight elevators.Glass: This type of passenger has a request percentage of 5%. Glass passengers have fragile items that need to be transported and are more likely to be picked up by glass elevators. public abstract class Passenger { public static int passangerCounter = 0; private String passengerID; protected…arrow_forwardPythonarrow_forward
- Pythonarrow_forwardHow do I take a long number input, validate the input as a long number and then subsequently use it in a different class? Basically, I want to input and validate a 15-16 digit long number (to exclude string and float), fetch it again to validate it with a different set of conditions in a different or subsequent class.arrow_forwardIn this project, a rational number is defined as a fraction in which the numerator and denominator are integers with the denominator being non-zero. Requirements To ensure consistency among solutions each implementation must implement the following requirements. • Your implementation should reflect the definition of a simplified rational number at all times. • A long (integer) is used to represent both the numerator and denominator. • The Rational class must be able to handle both positive and negative numbers. • The rational number must be in simplest form after every operation; that is, 8 6 shall be immediately reduced to 4 3 . In order to simplify a rational number properly, use the the Euclidean Algorithm to determine the greatest common divisor of the two numbers. • All methods that have an object as parameter must be able to handle an input of null. • By definition, the denominator of a fraction cannot be zero since it leads to an undefined value. In Java, this division by zero…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