Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
Question
Book Icon
Chapter 2, Problem 31P
Program Plan Intro

Ecosystem

Program plan:

  • Import the required java packages.
  • Create the class Animal,
    • Declare the array variable to fill the river.
    • Declare the constructor.
    • Define the print() function to read the size of river.
    • Define the printl() function to read the length of array.
    • Define the leftMove() function to fill ecosystem of river using bear, fish and null values with the help of random function.
    • Define the rightMove() function to fill ecosystem of river using bear, fish and null values with the help of random function.
    • Define the method check() to check the length of array elements and based on the value it calls the function to fill the ecosystem.
  • Define the main() function,
    • Declare the object for random() function.
    • Declare the object for Animal class.
    • Read the input using scanner class.
    • Fill the ecosystem with bear, fish and null values using the random() function.
    • Read the number of time steps.
    • Print the simulation ecosystem after each step.

Blurred answer
Students have asked these similar questions
Create a Java program   5. Stand out, Fit in by CodeChum Admin A good spy can always recognize another spy. No matter how good the disguise or how well they blend in, something about spies will always stand out and make them unique.   For your final exam in Spy school you have to distinguish spies that are hiding in plain sight and among the public. You're given a multidimensional array that shows the people in a certain area. A spy is found if there is at least one of the people that is unique from all the others.   Inputs 1. Number of rows of the multidimensional array   2. Number of columns of the multidimensional array   3. Elements of the multidimensional array Each element is within the range: 0 <= n <= 10   Sample Output Enter the number of rows: 3 Enter the number of columns: 3 1 2 2 7 3 8 4 4 3 SPY   Expected Output Enter the number of rows: 4 Enter the number of columns: 3 4 3 3 2 3 6 5 4 6 3 5 2 NONE   Expected Output Enter the number of rows: 4 Enter the…
2. Write a Java program that would resemble a payroll system. An input window which will accept the employee number and the number of days of rendered work. A 2d-arraylist that contains the employee number and the rate per day is to be searched and used to compute for the gross salary. Gross salary is computed by multiplying the number of days of rendered work by rate per day of the particular employee. If the gross salary computed is greater than 100,000 the tax is 20% of the gross salary, otherwise, the tax is 10%. Deduct the tax from the gross salary to get the net pay. Display the employee number, gross salary, tax deduction, and the net pay in an output window. Design your own input/output windows.
Write a Java program (Hangman.java) to play the classic word game Hangman. In the game, a word is randomly selected from an array of possible words. Then, the user is prompted to guess letters in the word one at a time. When the user makes a correct guess, all instances of that letter in the word are shown. When all letters in the word have been guessed, the game ends and the score (number of missed guesses) is displayed. A user can play the game multiple times if they choose.   Here is a sample run of a correct program (user input indicated by orange text):Enter a letter in word ******** > cEnter a letter in word c******* > rEnter a letter in word c******r > s       s is not in the wordEnter a letter in word c******r > tEnter a letter in word c****t*r > mEnter a letter in word c*m**t*r > t       t is already in the wordEnter a letter in word c*m**t*r > pEnter a letter in word c*mp*t*r > oEnter a letter in word comp*t*r > eEnter a letter in word comp*ter >…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education