Answer:
w is 25.0 x is 1.0
Practice Program
Our goal is to write a program that computes the following sum:
sum = 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6
(This may look like a pointless thing to do, but you will see such sums in calculus, where they are called harmonic series.) Here is a skeleton of the program:
A few notes on the program:
- The class
HarmonicSeriesdescribes an object that can compute the sum we want. - The method
value()of that object will do the computation. - A
HarmonicSeriesconstructor exists automatically, even though the program doesn't explicitly describe one. - The class
HarmonicTestercreates aHarmonicSeriesobject, then usesvalue()to calculate the sum, then prints it out.
QUESTION 10:
Fill in the two blanks to complete the program. (This situation is very common in programming and it would be very good practice for you to think about this question before going on.)