Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Assignment Overview You are to include both of these recursive assignments in your code submission. Remember to well-document your code and submit your code

Java Assignment Overview You are to include both of these recursive assignments in your code submission. Remember to well-document your code and submit your code and output as text file. All the methods are static and to be included in a class named Recursives, so that a test program can directly call these methods via the class name without creating objects of the class. In addition, write a test program (within Main) to test these recursive methods. 1 Divide and Conquer A detachment of n soldiers must cross a wide and deep river with no bridge in sight. They noticed two boys playing in a rowboat by the shore. The boat is so tiny, however, that it can only hold two boys or one soldier. How can the soldiers get across the river and leave the boys in joint possession of the boat? Write a recursive method to solve the problem with this header: 1 public static void crossRiver ( int n ) Your output should look like this for two soldiers:

2 soldiers ----> 0 soldiers, 2 boys

2 soldiers, 1 boy <---- 0 soldiers, 1 boy

1 soldier, 1 boy ----> 1 soldier, 1 boy

1 soldier, 2 boys <---- 1 soldier

1 soldier ----> 1 soldier, 2 boys

1 soldier, 1 boy <---- 1 soldier, 1 boy

0 soldiers, 1 boy ----> 2 soldiers, 1 boy

0 soldiers, 2 boys <---- 2 soldiers

Test your implementation with n = 2; 3; 4; 5 soldiers.

Hint: To show the process, you need to write another method to display how one solider crosses the river

2 Binary Conversion Write a method that takes a positive integer n as a parameter and returns its binary representation as String.

Write a recursive method to solve the problem with this header:

1 public static String integerToBinary (int n )

Hint: repeatedly divide 2 into n and read the remainders backwards. Test your implementation with n = 1; 11; 47; 483648.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design A Practical Approach

Authors: Marilyn Campbell

1st Edition

1587193175, 978-1587193170

More Books

Students also viewed these Databases questions