Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your method should accept a real number as a parameter representing a maximum limit, and should repeatedly add terms of the sequence until the overall

Your method should accept a real number as a parameter representing a maximum limit, and should repeatedly add terms of the sequence until the overall sum of terms meets or exceeds the maximum limit that was passed. For example, if your method is passed the value of 2.0, you should add terms of the sequence until the sum of all those terms is at least 2.0. The method should both return the final sum, in addition to printing out the fractions used and the final sum. 1/1 + 1/2 + 1/3 + 1/4 = 2.083333333333333 (Despite the fact that the terms keep getting smaller, the sequence can actually produce an arbitrarily large sum if enough terms are added.) If your method is passed any value less than 1.0, the value -1.0 should be returned. Other sample calls: sequenceSum(2.0); a. Prints : 1/1 + 1/2 + 1/3 + 1/4 = 2.083333333333333 b. 2.083333333333333 is returned sequenceSum(2.5); a. Prints : 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 + 1/7 = 2.5928571428571425 b. 2.5928571428571425 is returned sequenceSum(4.0); a. Prints : 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 + 1/7 + 1/8 + 1/9 + 1/10 + 1/11 + 1/12 + 1/13 + 1/14 + 1/15 + 1/16 + 1/17 + 1/18 + 1/19 + 1/20 + 1/21 + 1/22 + 1/23 + 1/24 + 1/25 + 1/26 + 1/27 + 1/28 + 1/29 + 1/30 + 1/31 = 4.02724519543652 b. 4.02724519543652 is returned sequenceSum(0.99); a. Prints : Error: must be larger than one. b. -1.0 is returned Remember that your code will both PRINT and RETURN. So keep that in mind

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Discuss alternative routes of subcontractor internationalization.

Answered: 1 week ago