Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I do not think that you are on a right way. First you cannot store "honda" or "toyota" in int array. So you need String array. The first column looks like index, so you do not have to store it in your array at all.</p> <p>Second, the example is not OO enough. I'd suggest you the following.</p> <p>Create class Vehicle:</p> <pre><code>public abstract class Vehicle { private String name; // getters, setters, constructor... } </code></pre> <p>Then create classes Car and Bicycle that extend Vehicle. These classes can contain other data:</p> <pre><code>public class Car extends Vehicle { public static enum Type {PICKUP, }; // add here other types private String model; private int doorsCount; private Type type; } </code></pre> <p>Now create class Garage:</p> <pre><code>public class Garage { private List&lt;Vehicle&gt; vehicles; // other fields and methods relevant for garage. } </code></pre> <p>This is the time to create static array of garages:</p> <pre><code>private static Garage[] garages = new Garage[100]; </code></pre> <p>You can populate it using static initializer (I assume here existence of convenient constructors I did not mention in my explanation):</p> <pre><code>static { Vehicle honda = new Car("honda", 4); Vehicle toyota = new Car("toyota", 2); Vehicle bicycle = new Bicycle("bicycle"); garaghes[0] = new Garage("First", new Vehicle[] {honda, toyota, bicycle}); Vehicle fiesta = new Car("ford", "fiesta"); Vehicle pickup = new Car("ford", Car.Type.PICKUP); garaghes[1] = new Garage("Second", new Vehicle[] {fiesta, pickup}); } </code></pre> <p>I believe your Prof will be satisfied. Good luck!</p>
 

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