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 (7th Edition)
- How 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_forwardSo I'm not able to add a third photo, but the last little bit says... Here are the details of all students:ID: 83557 | Grade: AID: 80992 | Grade: C+ID: 81483 | Grade: B- Since there are 2 questions, separate them as neededarrow_forward1. Implement the above system using inheritance in the best possible way. Keep every object size as small as possible. Implement all methods (setter/getter/constructors and destructors) Note that the region area is 0 while the city is len*width and the country is the sum of their cities. 2. Create array of countries called Arab of 22 countries, Write a function fill that fills the arrav Arab 3. Write a method that finds the city that has the max area in a country 4. Write a method that sorts the cities in a country from the largest to the smallest area 5. Write a function that retums array of countries of the same area of Arab 6. Write a function that compares between two countries. It returns true if countryl area greater than country2 area. 7. Write a function to move a city from one country to another.arrow_forward
- I already have the code for the assignment below, but the code has an error in the driver class. Please help me fix it. The assignment: Make a recursive method for factoring an integer n. First, find a factor f, then recursively factor n / f. This assignment needs a resource class and a driver class. The resource class and the driver class need to be in two separate files. The resource class will contain all of the methods and the driver class only needs to call the methods. The driver class needs to have only 5 lines of code The code of the resource class: import java.util.ArrayList;import java.util.List; public class U10E03R{ // Recursive function to // print factors of a number public static void factors(int n, int i) { // Checking if the number is less than N if (i <= n) { if (n % i == 0) { System.out.print(i + " "); } // Calling the function recursively // for the next number factors(n, i +…arrow_forwardWhat is the best way to go about this whole code with the given instructions?arrow_forwardPlease Solve Part B onlyarrow_forward
- This assignment is supposed to represent a group of students in a course. A group of students in a course will be assigned an assignment and produce a collection of assignment results. The results will be used to figure out grade statistics. The grade they receive for their work on the assignment is entirely dependant on the student's energy level. If the student works on many assignments without sleeping their grade will suffer. You will implement four classes (Assignment, AssignmentResult, Student, and Course), they will depend on each other in the order they are listed. Hint: Work on the methods in the order they are found in the documentation below, implement the getter and setter methods before the more complicated methods. Work on the Assignment class, AssignmentResult class, Student class and Course class in that order. Make sure you don't name your class variables the same name as you class's methods. In other words if you have method named id you cannot have a class…arrow_forwardAre there obvious improvements that could be made here with respect the software design for Squares and Circles? What programming constructs were you familiar with, and which did you need to look up? Assume we used a separate array for Squares and for Circles rather than one unifying Object array. How would this complicate the task of adding a new Shape (say, a Triangle) to our ObjectList class?arrow_forwardInstructor note: This lab is part of the assignment for this chapter. This lab uses two Java files, LabProgram.java and SimpleCar.java. The SimpleCar class has been developed and provided to you already. You don't need to change anything in that class. Your job is to use the SimpleCar class to complete the specified tasks in the main() method of LabProgram.java Given two integers that represent the miles to drive forward and the miles to drive in reverse as user inputs, create a SimpleCar object that performs the following operations: Drives input number of miles forward Drives input number of miles in reverse Honks the horn Reports car status The SimpleCar class is found in the file SimpleCar.java. Ex: If the input is: 100 4 the output is: beep beep Car has driven: 96 milesarrow_forward
- We're going to explore the law of large numbers here with a dice rolling program. Seed the random number generator with the current time and then roll three 6-sided dice (often described as 3d6) a total of 1,000,000 times and keep track of the number of times each sum 3 - 18 occurs. Be sure to separate all functions and methods (if you chose to use a class or structure) into both the prototype and an implementation below the main. 1. Build a regular c-type function that returns a random number between 3 - 18. This will simulate a single roll of three dice. Use the prototype: int rollDice(void);2. In the main, roll the dice 1,000,000 times and tally up the results in an array. I DO NOT want each individual roll printed to screen. Let the index represent the number rolled and the value will represent the number of times that number has been rolled. For example, a[3] = 5357 a[4] = 14750...a[18] = 4981 This array set-up will mean that the result 3 occurred 5,357 times and the…arrow_forwardWrite a method for the farmer class that allows a farmer object to pet all cows on the farm. Do not use arrays.arrow_forwardExplain why it is preferable to have accessors to private types rather than making the types public, keeping in mind the three reasons that are given below.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