I am very new to Java and am having a difficult time grasping the concepts being taught in my class. I think what keeps throwing me off is that the more I research the more I find that people do things differently. There are so many ways to do things how do I know if I am doing them right?
I have an assignment due this week in which we make changes to our existing application. The application has two classes. In one of the classes there is an array of items. I need to create a static mehtod in the other class that totals the value of the elements in the array.
Am I on the right track with the following code?
//Caluclate order total and return value
public static float orderTotal
//Create for loop
for(int i = 0; i <items.length (); i++)
sum +=myArray [i];
If I am on the right track how does the store items class know what the items arrray is since it was specified in the cash register class?
If the items array is public, then the other class can directly access the array. So if the array is called "items" and the class it resides in is called "MyClass", you would access the array by calling "MyClass.items"