Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

* You are given a map indicating the elevation of * a small area like a desk. A ball is placed on the desk. *

* You are given a map indicating the elevation of

* a small area like a desk. A ball is placed on the desk.

* The ball will roll downhill going north south east or west.

*

* The ball always starts at position 1,1

*

* It will always choose the path of steepest descent.

* It will eventually come to rest when it is at a position

* where all neighboring positions are higher/equal.

* Return the elevation of that position.

*

* You can assume that map will be such that the ball

* will always come to rest without moving through an edge

*

* You can assume there will always be one steepest

* position for the ball to go to

*

* For example, in an array like this:

* 9999

* 9549

* 9999 yields 4

* The ball would start in 1,1 (5) rolls to 4 and stops

*

* 99999999999

* 98711111199

* 96999999999

* 95444444399

* 99999999999 yields 4

* The ball starts at 8, follows steepest decent to 6

* Then at the first 4 there is no lower position so it

* stops

*

* @param map map indicating elevation

* @return height where the ball stops

public void testBallRestElevation() {

int[][] array1 = {

{9,9,9,9,9,9},

{9,8,5,4,9,9},

{9,7,9,9,9,9},

{9,7,5,2,2,9},

{9,9,9,9,9,9}};

assertEquals(4,MapAnd2DArrayHomework.ballRestElevation(array1));

int[][] array3 = {

{9,9,9,9,9,9},

{9,8,9,4,1,9},

{9,7,9,9,2,9},

{9,6,5,4,3,9},

{0,9,9,9,9,9}};

assertEquals(1,MapAnd2DArrayHomework.ballRestElevation(array3));

int[][] array2 = {

{9,9,9,9,9,9},

{9,8,6,4,9,9},

{9,5,9,9,9,9},

{9,5,5,2,2,9},

{9,9,9,9,9,9}};

assertEquals(5,MapAnd2DArrayHomework.ballRestElevation(array2));

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Case Studies In Business Data Bases

Authors: James Bradley

1st Edition

0030141346, 978-0030141348

More Books

Students also viewed these Databases questions

Question

3. What can be done about it?

Answered: 1 week ago

Question

Question May a taxpayer roll over money from an IRA to an HSA?

Answered: 1 week ago

Question

Question What is the doughnut hole in HSA coverage?

Answered: 1 week ago