Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A few things to fix in your first example:</p> <ol> <li><p>Right now, <code>j &lt; circles[0].length</code> means that only one column is being searched: column <code>0</code>. You'll want <code>j &lt; circles[i].length</code> to search every column by row.</p></li> <li><p><code>if (temp == r)</code> means you're comparing a <code>Circle</code> and a <code>double</code>. I'm not familiar with the circle class, but I believe you'll want to replace instead of <code>Circle temp = circles[i][j]</code> with <code>double temp = circles[i][j].getRadius();</code>.</p></li> <li><p>You want to return as soon as you find the matching <code>Circle</code>, so you have some things a little backwards. With my new revisions, <code>if (temp == r)</code> will now activate the code if you have found the correct radius. That means below that <code>if</code> statement, you'll want <code>return {i, j};</code>. That will return the current circle's (which has the correct radius) indicies.</p></li> <li><p>The last statement will be called if none of the radius tests return true, so where you have <code>return circles.indexOf(r);</code>, you'll want <code>return {-1, -1};</code>.</p></li> <li><p>Since arrays are 0-based, and less than already means one minus the value, you do not need <code>- 1</code> in <code>i &lt; circles.length - 1</code></p></li> </ol> <p>On your second example:</p> <p>Your <code>findCircleWithRadius</code> method has two paramaters: a <code>Circle[][]</code> and a <code>double</code>. That means you'll need to give it those. The method you created is not called from a double, as well, so you can't say <code>r1.findCircleWithRadius();</code> Additionally, you need to use the <code>int[]</code> that the <code>findCircleWithRadius</code> passes you to get those <code>Circle</code>'s. Therefore, your first lines in <code>swapCircles</code> should be:</p> <pre><code>int[] rad1 = this.findCircleWithRadius(circles, r1); // Get the coordinates of the first circle by passing the 2D array, and the radius you're looking for. int[] rad2 = this.findCircleWithRadius(circles, r2); // Get the coordinates of the second circle by passing the 2D array, and the radius you're looking for. Circle radius1 = circles[rad1[0]][rad1[1]]; // Circle 1 is equal to the Circle in the array that has coordinates of the first index in the coordinates, and the second index of the coordinates. (circles[x, y]) Circle radius2 = circles[rad2[0]][rad2[1]]; // Circle 2 is equal to the Circle in the array that has coordinates of the first index in the coordinates, and the second index of the coordinates. (circles[x, y]) </code></pre> <p>In conclusion, the completed code with my revisions will be as follows:</p> <pre><code>public int[] void findCircleWithRadius(Circle[][] circles, double r) { for(int i = 0; i &lt; circles.length; i++) { //search the row for(int j = 0; j &lt; circles[i].length; j++) { //search each column double temp = circles[i][j].getRadius(); if(temp == r) return {i, j}; } } return {-1, -1}; } public static void swapCircles(Circles[][] circles, double r1, double r2) { int[] rad1 = this.findCircleWithRadius(circles, r1); int[] rad2 = this.findCircleWithRadius(circles, r2); Circle radius1 = circles[rad1[0]][rad1[1]]; Circle radius2 = circles[rad2[0]][rad2[1]]; Circle temp2 = radius2; radius2 = radius1; radius1 = temp2; } </code></pre> <p>Otherwise, everything else is looking pretty good! I hope you did well on your quiz! Please let me know if you have any further questions about anything I have said so I can make sure you understand this fully.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload