so how would you use that with a completely different java file but in the same package
public static void main (int[] args)
{
int [] HotDog = {18,8,10,0};
int [] ToastedChicken = {25,8,17,0};
int [] ToastedSteak = {30,8,22,0};
int [] ToastedEggT= {20,8,6,6};
int [] ToastedSteakE={36,8,22,6};
int [] ChickenRoll = {25,8,17,0};
int [] SteakRoll = {30,8,22,0};
int [] EggTomato = {20,8,6,6};
int [] CheeseTomato = {20,8,6,6};
int [] steakEgg = {36,8,22,6};`
IE here
if (contents == "Hot Dog")
{jLabel2.setText(HotDog[2]); }
Your arrays are currently local to the method main. If you move them outside of the main method (exactly as they are) then they would be visible to other classes bin the same package as they would have package access. You will need to have a reference to that class (unless you make them static). In the example below I am calling the class X
Also it is comon practice in java to name variables in camelCase. For example chickenRoll
You will need to make them static. For example:
Then you can use them in any class in the same package like:
And i will try to make those
Array
asstatic
, so all the class trying to access these arrays gets the same array...I could have also used
Singleton Principle with Composition
here...but thats overkill for this..