Scott M Summers wrote:Yes, I declared it globally.
Scott M Summers wrote:I am referring to Java. And are you saying there are no global variables in Java? And do you have any information that relates to my question?
Campbell is right. In Java, every variable must be declared in a class. You can't have a "global" variable the way you can in some other languages.
Mike. J. Thompson wrote:Arrays in java do not have a splice method or a remove method. You can't change the size of an array, and there is no in built support for removing elements from an array.
The advice you were given was to switch to using a List (which does have a remove method). However if this is an assignment you may have been given instructions to use an array.
Where did you get the idea about splicing? And what instructions were you given?
Unfortunately, the search has led you to the wrong place. It is unfortunate that you have to use arrays because your array has 16 empty places which point to null, and nulls are potentially dangerous. You need to avoid using element 11 for example. I suggest you have a count variable which counts how many elements the array contains which are “real”, so whenever you add an element you increment count and vice versa. Also find out about copying parts of arrays. Look in the System class.
Scott M Summers wrote: . . .
I google'd how to delete an index in an array and I found splicing.
. . .
Jason Bullers wrote:You can't access it because the system_task_objects is only in scope in your WorkOrders() method. As Campbell pointed out earlier, I think you intended that method to be a constructor. You should read up on how to declare those and how write a class correctly. That should help solve your current problem.
Also, as a side note: you should use camelCase for naming your variables (so systemTaskObjects and not system_task_objects).
Campbell Ritchie wrote:The type and location of that array keep changing.
Yes, you can. That is the problem. But it doesn't do what you think it does.
Carey Brown wrote:. . . you can't do. . .
Scott M Summers wrote:[That's interesting, that is not what my CS teachers have taught.
No, they are perfectly legal. That code will compile happily. It will run too, and do what the OP doesn't expect.
Winston Gutkowski wrote:. . . all those '|'s in your case statement - which are illegal in the context your using them anyway. . . .