Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 18.8, Problem 18.8.4CP
Program Plan Intro
Recursive method:
A method which is called again and again by itself is called as recursive method. With the help of recursive method, it is possible to solve certain problems more quickly and easily.
Base case: The recursion method contains a base case which is used to halt the recursion.
Recursive call: When the function itself calls the same function is called as recursive call.
“displayTriangles ()” method:
- The “displayTriangles ()” method is used to display triangles by creating a triangle using “Polygon triangle = new Polygon ()” statement.
- This function get all the points using “getPoints ()” function.
- This method is a recursive method which contains base case and recursive call.
- In this method, the base case is present in the “if” statement.
- “if (order == 0)”
- In this method, the base case is present in the “if” statement.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
This should give you an error notice on the Code Pad. setValue(5); The error notice isn't particularly helpful. Can you figure out what's wrong with this setValue call and fix it? It's also worth remembering this error message because it stems from a common beginner's blunder.
this code is missing the duplicate name error. How can this be added?
Implement the "Remove song" function. Prompt the user for the unique ID of the song to be removed.Ex:
REMOVE SONG
Enter song's unique ID: JJ234
"All For You" removed
Chapter 18 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Ch. 18.2 - What is a recursive method? What is an infinite...Ch. 18.2 - Prob. 18.2.2CPCh. 18.2 - Show the output of the following programs and...Ch. 18.2 - Prob. 18.2.4CPCh. 18.2 - Prob. 18.2.5CPCh. 18.2 - Write a recursive mathematical definition for...Ch. 18.3 - Prob. 18.3.1CPCh. 18.3 - What is wrong in the following methods?Ch. 18.3 - Prob. 18.3.3CPCh. 18.4 - Describe the characteristics of recursive methods.
Ch. 18.4 - Prob. 18.4.2CPCh. 18.4 - Prob. 18.4.3CPCh. 18.5 - Prob. 18.5.1CPCh. 18.5 - Prob. 18.5.2CPCh. 18.5 - What is a recursive helper method?Ch. 18.6 - Prob. 18.6.1CPCh. 18.6 - How does the program get all files and directories...Ch. 18.6 - How many times will the getSize method be invoked...Ch. 18.6 - Will the program work if the directory is empty...Ch. 18.6 - Will the program work if line 20 is replaced by...Ch. 18.6 - Will the program work if lines 20 and 21 are...Ch. 18.7 - Prob. 18.7.1CPCh. 18.8 - Prob. 18.8.1CPCh. 18.8 - Prob. 18.8.2CPCh. 18.8 - How many times is the displayTriangles method...Ch. 18.8 - Prob. 18.8.4CPCh. 18.8 - Prob. 18.8.5CPCh. 18.9 - Which of the following statements are true? a. Any...Ch. 18.9 - Prob. 18.9.2CPCh. 18.10 - Identify tail-recursive methods in this chapter.Ch. 18.10 - Rewrite the fib method in Listing 18.2 using tail...Ch. 18 - Prob. 18.1PECh. 18 - Prob. 18.2PECh. 18 - (Compute greatest common divisor using recursion)...Ch. 18 - (Sum series) Write a recursive method to compute...Ch. 18 - (Sum series) Write a recursive method to compute...Ch. 18 - (Sum series) Write a recursive method to compute...Ch. 18 - (Fibonacci series) Modify Listing 18.2,...Ch. 18 - Prob. 18.8PECh. 18 - (Print the characters in a string reversely) Write...Ch. 18 - (Occurrences of a specified character in a string)...Ch. 18 - Prob. 18.11PECh. 18 - (Print the characters in a string reversely)...Ch. 18 - (Find the largest number in an array) Write a...Ch. 18 - (Find the number of uppercase letters in a string)...Ch. 18 - Prob. 18.15PECh. 18 - (Find the number of uppercase letters in an array)...Ch. 18 - (Occurrences of a specified character in an array)...Ch. 18 - (Tower of Hanoi) Modify Listing 18.8,...Ch. 18 - Prob. 18.19PECh. 18 - (Display circles) Write a Java program that...Ch. 18 - (Decimal to binary) Write a recursive method that...Ch. 18 - (Decimal to hex) Write a recursive method that...Ch. 18 - (Binary to decimal) Write a recursive method that...Ch. 18 - (Hex to decimal) Write a recursive method that...Ch. 18 - Prob. 18.25PECh. 18 - (Create a maze) Write a program that will find a...Ch. 18 - (Koch snowflake fractal) The text presented the...Ch. 18 - (Nonrecursive directory size) Rewrite Listing...Ch. 18 - (Number of files in a directory) Write a program...Ch. 18 - (Game: Knights Tour) The Knights Tour is an...Ch. 18 - (Game: Knights Tour animation) Write a program for...Ch. 18 - (Game: Eight Queens) The Eight Queens problem is...Ch. 18 - Prob. 18.35PECh. 18 - (Sierpinski triangle) Write a program that lets...Ch. 18 - (Hilbert curve) The Hilbert curve, first described...Ch. 18 - (Recursive tree) Write a program to display a...Ch. 18 - Prob. 18.39PE
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- When is it appropriate to adopt the direct method in order to prevent a deadlock? We kindly request that you refrain from providing comments that are handwritten and that only include a single word, phrase, or sentence. I would be grateful if you could help me understand it.arrow_forwardCreate some Student objects. Call the getName method on each object. Explain what is happening.arrow_forwardWhat happens when you try to look up a value and the key does not exist in the map?arrow_forward
- Implement the "Add player" menu option. Prompt the user for a new player's jersey number and rating. Append the values to the two vectors. Ex: Enter a new player's jersey number: 49 Enter the player's rating: 8arrow_forwardcan you fill this one with entitties?arrow_forwardWhat is wrong in the following code? How do you fix it?title = "Chapter " + 1arrow_forward
- After using this. s2[idx2] = s1 [idx1]. It is still not working. Would you please run the code before posting the answer? Thank you.arrow_forwardFinding the maximum value in a BST. Students need to write the code.arrow_forwardLet's finish working on our booking system. The last part for our booking system will be to manage multiple flights. To do this, we'll modify our program's command list. The command "create [id] [cap]" will try to create a new empty flight with ID [id] and capacity [cap]. The command "delete [id]" will try to remove the flight with ID [id]. The command "add [id] [n]" will try to add n reservations to the flight with ID [id]. The command "cancel [id] [n]" will try to cancel n reservations from the flight with ID [id]. If an operation fails for any reason, the program will issue the message "Cannot perform this operation". You can add a more helpful message to identify why the operation failed. The command "quit" will stop the execution of the program. For the sake of simplicty, let's limit the maximum number of handled flights to ten. Use the code from your previous exercise as a starting point. Note that we need to add an access method to the flight id field. PLS ANSWER…arrow_forward
- What is a HashMap? What is its purpose and how do you use it? Answer these questions in writing, and use the Java library documentation of Map and HashMap for your responses. Note that you will find it hard to understand everything, as the documentation for these classes is not very good. We will discuss the details later in this chapter, but see what you can find out on your own before reading on.arrow_forwardWhich one is NOT true about the following code? Select one: a. The setUp() method tests if it creates properly aList and anElement. b. The remove() method tests if the remove() method in the adaptee removes properly anElement from aList. c. The add() method tests if the add() method in the adaptee adds properly anElement to aList. d. The add() method tests if the add() method in the adaptee increases the size of aList by 1 when anElement is added to aList. e. The remove() method tests if the remove() method in the adaptee decreases the size of aList by 1 when anElement is removed from aList.arrow_forwardPlease come up with some scenario where mocking is required, write the Python class, and the Python unit test that included the patch that enables the mocking. You may patch a single value using return_value, or multiple values with side_effect. from territory import Territoryfrom army import Armyfrom territory_test import TestDoBattle t = Territory(10, Army())t.do_battle(Army())print(t.curr_territory) unittest.main() ----- class Army:def get_curr_strength(self):return 0 # pretend there is code here that returns an actual value ------ from army import Armyclass Territory:def __init__(self, initial_territory, this_army):self.curr_territory = initial_territoryself.this_army = this_army def do_battle(self, enemy_army):self.curr_territory += self.this_army.get_curr_strength() - \enemy_army.get_curr_strength()------ something similar to this code: from territory import Territoryfrom army import Armyimport unittestfrom unittest.mock import patch class…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- New Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage Learning
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning