Question: a) Write a method getNextPoint that takes as input three doubles parameters. The first parameter is a double which represents the height of the previous

a) Write a method getNextPoint that takes as input three doubles parameters. The first parameter is a double which represents the height of the previous point in the mountain range. The second parameter is a double which is the possible steepness between adjacent points. Finally, the last parameter is a double, which is the maximum height of any point in the mountain range. This method takes the previous point in the mountain range, and creates a height for the new point. The difference between the previous height and the new point is based on a random change controlled by the steepness parameter. For example, let the previous point be 10.5, and the steepness parameter be 3.0. The new point must be 10.5 plus a random number in the range of -3.0 to 3.0. Therefore, the new point will be in the range of 7.5 to 13.5. This means that the larger the steepness parameter is, the larger the difference in height between one point in the mountain range and the next. Note that in the two example mountains provided, the steepness of the first example is much higher than that of the second example, and the mountains are much steeper. We also need to make sure that the height of the new point is not too large or too small. If the new point is above the maximum height (which is the third parameter to the method), then the new points height must be set to be equal to the maximum height. Similarly, if the new points height is below zero, then the new points height must be set to zero. To summarize, the new point is based on the old point, plus a change based on the steepness. The new points height cannot be above the maximum height, or below zero.Method for generating the heights of all points:

b)Write a method generateMountains to generate the heights for all points in the mountain range. This method takes three parameters. The first parameter is an integer value, which is the number of points for the mountain range. The second parameter is a double representing the steepness. Finally, the third parameter is a double which is the maximum height of the points in this mountain range. This method returns an array of doubles. The method must create the array of doubles, using the first parameter to this method as the size. Then, set the first point in this array to have a value of half of the maximum height of the mountain range. Then, iterate over the array and set each new point using the getNextPoint method. Note that this method must take the value of the previous point as a parameter.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!