Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your program is not counting the total nomber of houses correctly.</p> <p>For instance there are 19 houses here but only 18 are counted by the visit method. This is because you only visit cases that are "connected" to the powerplant.</p> <pre><code>15 22 , , , , , , , , , , . . . , , , , , , , , , , , . , , , , H , H H H - - + , , , , , , , , , , , , , , , , H H H . . | . , , , . , , , , , , , , , , , H H H = , | . , , , . . . , , , , , , , , , H H H = , | . , , , . . . , , , . . . . . , H H H = , | , , , , . . . . . . . . . . . , H H H = , | , , , , . . . , , . , , = = = = = = = = , | , , , . . . . , , X X X X , . . . . C C C C C C . . . . . . . X P X X , . . . . C C C C C C . . . . . . . X X X X - - - - - C C C C C C . . . . . . ~ X X X X . . . . . . . . . . . . . . . . ~ ~ ~ ~ . . . . . . . . . . . . . . . . . . ~ ~ ~ ~ ~ . . . . . . . . . . . . . . . . ~ ~ ~ ~ ~ ~ ~ . . . . . . . . . . . ~ ~ . ~ ~ </code></pre> <p>You can count the total amount of houses this way :</p> <pre><code> for (int i = 0; i &lt; row; i++) for (int j = 0; j &lt; col; j++) { grid[i][j] = sc.next(); if(grid[i][j].equals("H")){ totalHomes++; } } </code></pre> <p>Then count the actual number of powered houses this way (I used a new attribute homesPwrd (=0), only modified by this method, not sure what all your other integers are good for ...) :</p> <pre><code>public void visit (String[][] A, int x, int y, Pair pair, String oldSymbol, String newSymbol, int d) { if ((x &gt;= 0 &amp;&amp; y &gt;= 0) &amp;&amp; (x &lt; row &amp;&amp; y &lt; col) &amp;&amp; A[x][y].equals(oldSymbol)) { if (oldSymbol == "H") homesPwrd++; A[x][y] = newSymbol; dist.put(pair, d); q.addLast(pair); } } </code></pre> <p>Finally</p> <pre><code> System.out.println(totalHomes-homesPwrd + " of " + totalHomes + " are without power."); </code></pre> <p>Output</p> <p>1 of 19 are without power.</p> <pre><code> 1 of 19 are without power. ,,,,,,,,,,...,,,,,,,,, ,,.,,,,H,******,,,,,,, ,,,,,,,,,***..*.,,,.,, ,,,,,,,,,***=,*.,,,... ,,,,,,,,,***=,*.,,,... ,,,.....,***=,*,,,,... ........,***=,*,,,,... ,,.,,========,*,,,.... ,,****,....******..... ..****,....******..... ..***************..... .~****................ ~~~~.................. ~~~~~................~ ~~~~~~...........~~.~~ </code></pre>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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