Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>City</code> actually doesn't provide a static <code>getConnections()</code> method, since that doesn't make sense. The connections depend on an actual <code>City</code> instance and if you have access to one you can call <code>getConnections()</code> on it, even from a static method.</p> <p>This is the comment on the array list that is cloned in <code>getConnections()</code>:</p> <blockquote> <p>// Which cities are connected to <em>this one</em></p> </blockquote> <p>Note that this means you just can't get the connections without specifying <em>this</em> city (the one you get the connections for) and thus just can't call that method on the <code>City</code> class only.</p> <p>Comment on the method itself:</p> <blockquote> <p>Purpose: To retrieve a list of cities you can reach from <em>this one</em>.</p> </blockquote> <p><br></p> <p>Assuming your <code>determineRoute(...)</code> method might be static, it could look like this:</p> <pre><code>public static boolean determineRoute(City from, City to, ArrayList&lt;City&gt; flightRoute) { ArrayList&lt;City&gt; connections = new ArrayList&lt;City&gt;(); connections = to.getConnections(); //or from.getConnections(); what ever makes sense //connections is not used, so I assume you want to put them into flightRoute flightRoute.addAll(connections); return true; } </code></pre> <p>Your <code>determineRoute(...)</code> logic seems quite odd. I assume you want to actually calculate the route between the <code>from</code> and the <code>to</code> city, which you are not doing right now. Fixing that, however, is an exercise for you.</p> <p>You could then call that method in your main method (which <em>has</em> to be static) like this:</p> <pre><code>public static void main(String... args) { City berlin = new City("Berlin"); City beijing = new City("Beijing"); //fill the connections here ArrayList&lt;City&gt; route = new ArrayList&lt;City&gt;(); boolean success = determineRoute(berlin, beijing, route); } </code></pre>
 

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