Ask your own question, for FREE!
Computer Science 28 Online
OpenStudy (anonymous):

I'm confused about using multiple classes and using variables across them. Basically, I'm making a shopping cart with 3 classes: a driver, a cart, and a grocery item class. The code can be found here: http://www.cs.montana.edu/~sean.yaw/Teaching/Fall2014/111/Inlabs/Inlab3/Inlab3

OpenStudy (anonymous):

Question 1: Why can't I do a method to add a general item, instead of a specific "item1/2/3"? Question 2: I want to print the variable name, quantity, and number in the same line, but how how do I reference that information from the other class?

OpenStudy (e.mccormick):

Take a look at the class/static variables here: http://www.tutorialspoint.com/java/java_variable_types.htm So you can use gettrs and setters to return and return and modify a variable in an instance or the entire class. If the variable is a static one for the entire class then it is the same one in every object made from that class. The nuber of bicycles here is an example of this: http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html Let me know how much those help, if they don't, what you don't get, etc. We can go from there.

OpenStudy (anonymous):

Wow I didn't know about that java tutorial site. It's exceptionally useful. Thank you!!!!

OpenStudy (e.mccormick):

Yah, it is a reasonably good site.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!