Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

which contains a skeleton of the solution. You should complete thisskeleton (i.e

ID: 3614794 • Letter: W

Question

which contains a skeleton of the solution. You should complete thisskeleton (i.e., complete all the methods) without modifying what isalready there.

By the way, the skeleton will appear to have syntax errors in itwhen you open it. The reason is that all Java functions (methods returninga value) are supposed to contain a return statement to return their result.The functions in the skeleton, however, do not. Once you have addedappropriate return statements to all the functions, the errors will be gone.

(You are allowed to make changes to the given skeleton, if youfeel that that is necessary.But if the resulting design is considered by your instructor to beinferior to the one provided in the skeleton, your grade will reflectthat. And, in any case, you MUST make use of appropriate class methodsto structure your solution.)

Start Eclipse and create a new project, Lab5. Import intoyour Lab5 project the following file from K:CSE201Lab5 (seeLab 1 for instructions on howto import files in Eclipse):

Complete the Lab5 program according to the description below.If you don't remember how to create a project in Eclipse,see Lab 1 for instructions.

A Hailstone series is defined as follows: Start with any integer valuegreater than 0, say x. If x is even, then the next value in the seriesis x/2; if x is odd, then the next value in the series is 3x + 1. Now applythe same rules to create the next value in the series, and so on. The nameHailstone comes from the property that the values in such a series alternatebetween going up and down (forward for odd values and back for even values.)

For instance, here is the Hailstone series generated from starting value 17:

Note that if a Hailstone series ever reaches the value 1, then the nextvalue generated is 4, the next is 2, and the next is 1 again. Thus, whena Hailstone series reaches 1, then it has converged in the sensethat the rest of the series is 4,2,1,4,2,1, ... .

The Hailstone series is the subject of a long-standing mathematicalpuzzle: Given an arbitrary positive integer as a starting value, will theresulting Hailstone series converge as just described? For all positiveintegers of size at most 1.2x1012, it is known that the seriesdoes converge. To date, however, there is no formal proof that allsuch series must converge. (There is an interesting and readable articleabout the Hailstone series in the January 1984 issue of Scientific American.)

For this assignment, you will be writing a program that allows usersto enter a starting value from which the program computes the correspondingHailstone series. Thus, you can explore for yourself the behavior of theHailstone series.

Here is a sample interaction between a user and the program you will writein the Lab5 class (user inputs are in bold):

Your program should ask the user if he/she wants to have another Hailstoneseries computed. If so, the user should be prompted for a starting value,and the Hailstone series should be computed until it converges (the number1 is generated). Your program should then report to the user the numberof terms that were generated to reach the value 1 (counting the startingnumber as one of the terms generated) and the largest valuethat was generated while getting there. For instance, for the Hailstone seriesabove, generated from starting value 17, the number of terms generated is 13,and the largest value generated is 52. The entire process should thenbe repeated until the user does not want to have theprogram compute another Hailstone series. Note that it is not necessary tooutput the whole series (though you may find it helpful while testing anddebugging your solution).

A fundamental requirement for this lab is the use of good program decompositionand the definition and implementation of appropriate class methods. Submittedsolutions that do not exhibit a good design using appropriate methods willnot receive full credit. The skeleton provided represents a reasonablygood design for a solution.

You should read the comments in each method carefully and then fill inall the bodies making sure that your code implements the behavior describedin the comments. You should also make sure that the only way informationis passed around in your program from method to method is through eachmethod's given arguments.

One last note: This design forces you to duplicate the series generatingcode in two different places (the method computing the length of the series,and the method computing the largest term in the series). The reason for thisis a technical problem with the Java language. In Java there is no easy wayto write a method that returns two (or more) values. So if we wanted toavoid the duplication, we would have to make some other compromise in thedesign.

Make sure your program compiles and runs correctly before submitting. Tosubmit, use the Submit tool available on the Widows desktop to submit theLab5.java file from the Lab5project (the location of the project in the file system will bez:eclipseworkspaceLab5). Make sure that you select lab5from the list of Assignments. If you don't remember how to use the Submit tool,see Lab 1 for instructions.

Determine the starting

Explanation / Answer

What are you having problems with? I am sorry to say, but right now it looks like you want to copysomeone else's work. You just posted your assignment and did not include any of yourcode, or anything specific which puzzled you.