Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This lab is designed as a basic recursion overview. By the end of it, you should have enough recursive programming experience to have an elementary

This lab is designed as a basic recursion overview. By the end of it, you should have enough recursive programming experience to have an elementary understanding of the recursive problem-solving process. This process will be built upon in future assignments, as well as in future classes.

Using eclipse!

Problem:

For this lab, you will write a class called RecursionToolkit. In it are a number of recursive methods. You will then use a main method to test your code with the provided test information. If you are particularly savvy, you could write these as JUnit Test Cases (and will get a bit of extra credit as thanks for making my job easier). The methods, and their test cases, follow: (1) Harmonic Series

Write a method to calculate the nth term of the Harmonic Series. The series is defined as:

image text in transcribed

As an argument, your method should take n, corresponding to which nth term of the series the user wants. The return value is the result of the series up to that n. If the number is zero or negative, the result should be the integer 1 as a way of error handling. Examples:

harmSer(5) should return 2.283333333333333

harmSer(2) should return 1.5

harmSer(20) should return 3.597739657143682

harmSer(-5) should return 1

(2) Sum Digits

Write a method to sum all the digits in an integer. Return 0 if the input is negative.

sumDigits(1234) should return 10

sumDigits(9) should return 9

sumDigits(5032134) should return 18

sumDigits(-50) should return 0

(3) Recursive Sequential Search

Write a method to recursively search an array of Strings for a given target, using sequential search. Each call is only concerned with searching the current element otherwise, a recursive call (or return) should be made. Return a -1 if the element is not found, and the index of the element if the element is found

Searching the array {Apple, Orange, Grapefruit, Pear} for Orange, should return the integer 1. Searching for Pineapple, should return -1

(4) String Cleaning

Write a method for which, given a String, will clean redundant characters. That, characters that are the same and are neighbors should be reduced to one character.

For example, using the String yyzzza as an argument should return yza and Hello should return Helo.

co n= 1 + 1 + 1 + 1 n=1 14 1-3 1-2 1-n 8>

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

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions