Note that there are some explanatory texts on larger screens.

plurals
  1. PO'Use a static array'... what does that even mean?
    primarykey
    data
    text
    <p>I know what a static array is and how to use it in Java, but my Prof assigned us a program and for one of the many classes we had to create, he asked us to 'use a static array' in such a way that multiple objects will store their data there.</p> <p>For instance, if the objects were car garages, then each garage instance would store in a 100x3 static array their data:</p> <pre><code> 1, honda, four-door 3, toyota, two-door 1, bicycle, -1 1, ford, pickup 2, ford, fiesta 3, chevy, two-door 3, bicycle, -1 </code></pre> <p>The -1 indicates the end of each garage.</p> <p>That's a lousy example, but you get the idea.</p> <p>So, I am thinking that what he wants is kind of like this:</p> <p>In the demo class (which is the main), I will declare an instance of a class I made with the static array in it:</p> <pre><code> PublicAccessArray p1 = new PublicAccessArray(); </code></pre> <p>Then that class starts off like: </p> <pre><code> public class PublicAccessArray { public static int[][] accessArray; public static void PublicAccessArray() { accessArray = new int[100][3]; ... </code></pre> <p>And then my class that will create the objects to use the static array will look like:</p> <pre><code> public class ClassThatUsesTheStaticArray { public void ClassThatUsesTheStaticArray (PublicAccessArray array1) {... </code></pre> <p>So then back in the demo/main class I would instantiate those objects with:</p> <pre><code> ClassThatUsesTheStaticArray c1= new ClassThatUsesTheStaticArray (p1); </code></pre> <p>I think that's what he means, and I know that the static array should look like the example I gave (though it uses numbers as data/elements).</p> <p>I know he wants us to instantiate the ClassThatUsesTheStaticArray objects from the demo/main class and the only way I can see to do that would be to pass the p1 array to it.</p> <p>Does what I am doing seem to be the right way? I often an easier time doing the actual coding than figure out what my Prof. is actually asking us to do so I was wondering if that sounds like a way to 'use a static array'.</p>
    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.
 

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