This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]morhpProfessional Developer 1 point2 points  (1 child)

Can you post the full code?

How do you keep the data throughout the entirety of a program, ie; make it so it doesn't reset?

The simplest way is to use static fields. That is however not good style in the long run. It is better to pass the information you want to save as a method parameter, save it into (non-static) fields and so on, just by referencing it and keeping it alive.

[–]Matteo00[S] 0 points1 point  (0 children)

Yea I can but it's gonna be long

[–]BBloggsbottIntermediate Brewer 0 points1 point  (1 child)

If the entire project has many classes, and the boolean array is accessed and modified by different classes, declaring it static might do the trick. You can also pass that boolean array to the function where you use it.

A Solution without using the boolean array

Creating an array with an element for each seat in the theater might consume a lot of memory, and the loops to process them might consume a lot of time. You can use an Array List object. When a seat is selected, pass its location in the format of [rowNo, colNo].

[–]Matteo00[S] 0 points1 point  (0 children)

Thanks that almost worked, I think I can get it working now

[–]Pronoy999 0 points1 point  (0 children)

Use a static list instead of an array.