Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Write a single program containing several methods that will compute the sum of the first n terms of the series in the specific

1. Write a single program containing several methods that will compute the sum of the first n terms of the When you write the literal value 3.1415 Java assumes the data type is double. When you write 3.1415f you

1. Write a single program containing several methods that will compute the sum of the first n terms of the series in the specific manners outlined below. (Let n = 100,000 to start and if you have time, try a million terms.) a) Sum the series forwards (first term first), using type double variables and literals. b) Sum the series backwards (last term first), using type double variables and literals. sum the series forwards in two halves by computing the sum of the positive terms separately from the negative terms and then combining the results at the end. Use type double variables and literals. c) d) Sum the series backwards in two halves, computing the sum of the positive and negative terms separately, using type double variables and literals. e) Sum the series forwards (first term first), using type float variables and literals. f) Sum the series backwards (last term first), using type float variables and literals. 2. Have your program display the results from each of these methods in a table-like format, clearly labeling the output. Use 15 decimal places in your output. In a separate paragraph speculate about which result you consider the most accurate (including your calculator), and what accounts for any discrepancies, if there are any. You may also want to compare your result against the math library method log(). When you write the literal value 3.1415 Java assumes the data type is double. When you write 3.1415f you force the data type of the literal to be a float. The suffix 'f' is important when you need a literal to be a float type. I would expect the signature of each method to be of the following form: private static float sumForwards (int numberOfTerms) {...} This one satisfies le from above; each of the other methods will be similar. 1. Write a single program containing several methods that will compute the sum of the first n terms of the series in the specific manners outlined below. (Let n = 100,000 to start and if you have time, try a million terms.) a) Sum the series forwards (first term first), using type double variables and literals. b) Sum the series backwards (last term first), using type double variables and literals. sum the series forwards in two halves by computing the sum of the positive terms separately from the negative terms and then combining the results at the end. Use type double variables and literals. c) d) Sum the series backwards in two halves, computing the sum of the positive and negative terms separately, using type double variables and literals. e) Sum the series forwards (first term first), using type float variables and literals. f) Sum the series backwards (last term first), using type float variables and literals. 2. Have your program display the results from each of these methods in a table-like format, clearly labeling the output. Use 15 decimal places in your output. In a separate paragraph speculate about which result you consider the most accurate (including your calculator), and what accounts for any discrepancies, if there are any. You may also want to compare your result against the math library method log(). When you write the literal value 3.1415 Java assumes the data type is double. When you write 3.1415f you force the data type of the literal to be a float. The suffix 'f' is important when you need a literal to be a float type. I would expect the signature of each method to be of the following form: private static float sumForwards (int numberOfTerms) {...} This one satisfies le from above; each of the other methods will be similar.

Step by Step Solution

3.40 Rating (147 Votes )

There are 3 Steps involved in it

Step: 1

Heres an example in Java that computes the sum of the series using the specified methods java public ... 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

Visual C# How to Program

Authors: Paul J. Deitel, Harvey Deitel

6th edition

134601548, 134601793, 978-0134601540

More Books

Students also viewed these Programming questions

Question

=+ Is someone else already using the same name?

Answered: 1 week ago

Question

What is the key accomplishment of the UML?

Answered: 1 week ago