Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The Problem A Hailstone series is defined as follows: start with any integer value greater than 0 , say x . If x is even,
The Problem
A Hailstone series is defined as follows: start with any integer value greater than say If is even, then the next value in the series is ; if is odd, then the next value in the series is Now apply the same rules to create the next value in the series, and so on The name Hailstone comes from the property that the values in such a series alternate between going up and down up for odd values and down for even values.
For instance, here is the Hailstone series generated from starting value :
Note that if a Hailstone series ever reaches the value then the next value generated is the next is and the next is again. Thus, when a Hailstone series reaches then it has converged in the sense that the rest of the series is dots.
The Hailstone series is the subject of a longstanding mathematical open question: given an arbitrary positive integer as a starting value, will the resulting Hailstone series converge as just described? For all positive integers of size at most it is known that the series does converge. To date, however, there is no formal proof that all such series must converge. There is an interesting and readable article about the Hailstone series in the January issue of Scientific American.
For this assignment, you will write a program that allows users to enter a starting value from which the program computes and outputs the corresponding Hailstone series stopping with if it ever reaches After the initial program works, there are a number of other requirements to change it slightly, one step at a time, as explained below.
Setup
Follow these steps to set up a project for this lab.
Create a new Eclipse project by copying ProjectTemplate if needed, see Creating a New Project from a Project Template for details Name the new project Hailstone.
Open the src folder of this project and then open default package As a starting point you should use ProgramWithIOAndStaticMethod.java. Rename it Hailstone and delete the other files from the project if needed, see Creating a Program from a Skeleton also Renaming a Java Program for details
Method
Edit Hailstonejava including updating comments appropriately to ask the user for a positive integer and then compute and output the corresponding Hailstone series. The generation and output of the series should be done in a static method declared as follows copy the method header, including the documentation comment, from the browser and paste it into Eclipse, replacing only the myMethod method provided in the skeleton program:
Generates and outputs the Hailstone series starting with the given integ
cparam
the starting integer
aparam out
the output stream
private static void generateSeriesint SimpleWriter out
Copy Hailstone java to create Hailstone java rightclick on Hailstonejava to get the contextual popup menu and choose Copy, then rightclick on default package and choose Paste, providing the new name Hailstone Change generateseries including its Javadoc comments so that it also computes and outputs the length of the series.
Copy Hailstone java to create Hailstone java. Change generateSeries including its Javadoc comments so that
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started