Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Testing Two Dimensional Array Class, need help! /** * Demonstrates a two-dimensional array. * * @author Derek Green * @version November 6, 06 * modified

Testing Two Dimensional Array Class, need help!

/** * Demonstrates a two-dimensional array. * * @author Derek Green * @version November 6, 06 * modified by William Smith 6/7/2012 */ public class TestTwoDimArray { private final int rows = 10; private final int cols = 20; private final int diameter = 20; /* Add a two-dimensional Circle array field to hold your circles. */

/** * Creates an empty 2-dimensional Circle array. */ /* Write a constructor method that initializes the array. The first dimension should be given size rows, and the second dimension should be given size cols. */

/** * Fill the array with circles. */ /* Write a method called "fillArray" that fills the entire array with blue circles. Give all circles the same diameter using the field defined above. Circles in the same row should have the same yPosition. Circles in the same column should have the same xPosition. The yPosition for row 0 should be 0. The yPosition for row 1 should be diameter. The yPosition for row 2 should be 2*diameter... Continue this pattern for all rows. Use a similar pattern to set the xPosition of each circle in a given column. If you do this correctly, no circle will overlap another circle.

Once you get this working, then fix your code so that it does not add circles to positions in the array that are already occupied by a circle. You can tell whether a position is empty by checking if it contains null. */

/** * Add a random number of circles (between 1 and rows * cols). * Only need one loop here; */ /* Write a method called "addSomeCircles" that tries to add a random number of red circles to the array in a random fashion. The number of circles it tries to add should be between 1 and rows*cols, inclusive. For each circle choose a random row number and a random column number. The x and y positions of the circle should follow the plan used in the "fillArray" method. If the array has no circle at that position, add one, otherwise move on. Your method should return the number of collisions you had while adding circles. Remember, an empty element in the array will be equal (i.e., ==) to null. */

/** * Add a single circle at (row,col). * Make sure you account for arrays having positions from 0 to n and test for entering an invalid position */ /* Write a method called "addSingleCircle" that takes an integer parameter for the row and an integer parameter for the column. If the coordinates specify a valid position in the array, and the array has no circle at that position, then add a green one, otherwise do nothing. The x and y position of the circle should follow the plan used in the "fillArray" method. */ /** * Makes all circles in the array visible. */ /* Write a method called "makeAllCirclesVisible" that makes all circles in the array visible. */

/** * Makes all circles in the array invisible. */ /* Write a method called "makeAllCirclesInvisible" that makes all circles in the array invisible. */

/** * Remove all circles from the array. */ /* Write a method called "emptyArray" that removes all circles from the array (i.e. make them all null.) (Don't forget to make them all invisible first.) */ }

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions

Question

What impediments deal with customers?

Answered: 1 week ago

Question

305 mg of C6H12O6 in 55.2 mL of solution whats the molarity

Answered: 1 week ago