Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Question
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.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents 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 >…
Chapter 2 Solutions
Data Structures and Algorithms in Java
Ch. 2 - Give three examples of life-critical software...Ch. 2 - Give an example of a software application in which...Ch. 2 - Prob. 3RCh. 2 - Prob. 4RCh. 2 - Prob. 5RCh. 2 - Give a short fragment of Java code that uses the...Ch. 2 - Prob. 7RCh. 2 - Prob. 8RCh. 2 - Prob. 9RCh. 2 - Prob. 10R
Ch. 2 - Prob. 11RCh. 2 - Draw a class inheritance diagram for the following...Ch. 2 - Prob. 13RCh. 2 - Prob. 14RCh. 2 - If the parameter to the makePayment method of the...Ch. 2 - Prob. 16CCh. 2 - Most modern Java compilers have optimizers that...Ch. 2 - The PredatoryCreditCard class provides a...Ch. 2 - Modify the PredatoryCreditCard class so that a...Ch. 2 - Prob. 20CCh. 2 - Write a program that consists of three classes, A,...Ch. 2 - Prob. 22CCh. 2 - Prob. 23CCh. 2 - Write a Java class that extends the Progression...Ch. 2 - Redesign the Progression class to be abstract and...Ch. 2 - Use a solution to Exercise C-2.25 to create a new...Ch. 2 - Use a solution to Exercise C-2.25 to reimplement...Ch. 2 - Write a set of Java classes that can simulate an...Ch. 2 - Write a Java program that inputs a polynomial in...Ch. 2 - Write a Java program that inputs a document and...Ch. 2 - Prob. 31PCh. 2 - Write a Java program that simulates a system that...Ch. 2 - Define a Polygon interface that has methods area()...Ch. 2 - Prob. 35PCh. 2 - Write a Java program that can make change. Your...
Knowledge Booster
Similar questions
- Code using javaarrow_forwardJAVA PROGRAMMING OBJECT-ORIENTED PROGRAMMING Use the composite pattern to create a model of a scene of your choosing. It may be a scene from a picture, or a simulator, or a movie, or a videogame, or something else entirely.arrow_forwardYou have been hired at an open-air mine. You are to write a program to control a digger. For your task, you have been given a 'map' of all the underground resources in the mine. This map comes as a two-dimensional integer array. The array has n rows and k columns. Each integer is between zero and one hundred (inclusive). This array represents a grid map of the mine – with each row representing a different height level. Each square in the grid can contain valuable resources. The value of these resources can go from zero (no resources) to 100 (max resources). The grid maps the resources just below the surface, and down to the lowest diggable depths. The digger starts at the surface (so, just on top of the topmost row in the grid)—at any horizontal position between 1 and k. The digger cannot dig directly downwards, but it can dig diagonally in either direction, left-down, or right-down. In its first time-step, it will dig onto the first row of the grid. In its second time-step, it'll hit…arrow_forward
- Write a Java program that would resemble banking transactions of deposits, withdrawals, bank to bank transfers, and interest computations. A transaction input window is to be used in entering the account number, transaction code, and amount. Search a 2d-arraylist containing account number and the current balance, and then do the appropriate update on the 2d-arraylist depending on the transaction code. If the transaction code is “D”, update the current balance by adding the amount; if “W”, update the current balance by subtracting the amount from the current balance provided that withdrawal transaction is allowed (current balance must be greater than the amount to be withdrawn, and the resulting balance must not be less than 500). Display the updated 2d-arraylist before exiting the program. Design your own input/output windows. ( USE OOP CONCEPT AND JOPTION)arrow_forwardFor an array of objects The array can contain objects of different types at run time but must be defined as the same object type in Java code. The array can contain objects of different types at run time and can be defined as different object types in Java code. The array can't contain objects of different types at run time and must be defined as the same object type in Java code. The array can't contain objects of different types at run time but can be defined as different object types in Java code.arrow_forwardJAVA PROGRAMMING OBJECT-ORIENTED PROGRAMMING Create a model of a setting of your choosing by applying the composite pattern. It may be a scene from a photograph, or it could be from a simulator, or it could be from a movie, or it could be from a videogame, etc.arrow_forward
- do the following in JAVA GUIarrow_forwardwrite java program for the above questionarrow_forwardJAVA PROGRAMMING OBJECT-ORIENTED PROGRAMMING Create a model of a scene of your choosing by making use of the composite pattern. It may be a scene from a photograph, or it could be from a simulator, or it could be from a movie, or it could be from a video game, etc.arrow_forward
- Write a java program that Reads integer values into an array. Print the value in the array that appears the most.If more than one value appears the most, print the value that appears closest to the start of the input. Input Format The first line contains the number of integers in the array The second line contains the values in the array Constraints 1 <= size of array <= 10000 the elements of the array can be any legal java integer value. Output Format The value of the element that appears the most number of times. Sample Input 0 106 5 2 6 4 3 2 9 2 5 Sample Output 0 2 Explanation 0 The value 2 appears 3 times in the 10 element listarrow_forwardMust be in JAVA. Please show in simplest form and with comments. The correct UML Diagram MUST be provided as well with the solution. It will be flagged if the UML Diagram is not provided.arrow_forwardUsing Java GUI create hunting, two-player game, played on a board consists of n x n fields, where the first player (call him fugitive) tries to run away, while the second player (the hunter) tries to capture him/her. Initially, the character of the fugitive is at the center of the board, while the hunter has four characters (one at each corner). The players take turns moving their character (hunter can choose from 4) 1 step on the board (they cannot step on each others character). The objective of the hunter is to surround the fugitive in at most 4n steps, so it won’t be able to move.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education