The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Instance variable inside a method

I am working on a project where I need to return 3 values I understand I can only return one using a method alone! So I need to add 2 instance variables, that will return the other 2 values. Can someone please assist me in this? Here is my code, it may be completely wrong! I have used a larger font and commented as much as possible about where I am having a problem!

Re: Instance variable inside a method

I need to display total shipping, highest charge, and the lowest charge

When you say display, do you mean to use the println() statement to display the values on the console?

What are the names of the variables with the values you want to display? What class are they in?
Does the class with the computeShippingCharges() method have a reference to that class so the computeShippingCharges() method can access the variables you need to get to?

Re: Instance variable inside a method

Yes as far as I understand I need to use printf() to display the output. I need to display the highest input value and the lowest inputed value, also I need to display the accumulated total of the inputs. If I am not mistaking this is the reference to class? WebHost webHost; I may be wrong I new to Java.

Re: Instance variable inside a method

What variables hold the values you want to print in the computeShippingCharges() method?
What class are those variables located in?

Does the class that the computeShippingCharges() method is in have a reference to the class that contains those variables?

How did you get a 260+ line program without first testing the technique of how one class can get access to the variables in another class?
Have you tried writing a couple of classes with about 30 lines of code with variables and methods to test the techniques that are giving you a problem in the posted code? There is a lot of code here that is not part of your problem.

Re: Instance variable inside a method

I guess I am not following what your asking I am sorry the code has worked until I added this new step and it has all been tested up to this point I guess the easiest way to explain what I need to do is show smaller bits of code.

Re: Instance variable inside a method

Ok I see the confusion now because shipping is defined in public class WebHostOrder14 as well as highest and lowest, however highest and lowest is also defined in the overloaded constructor in WebHost. I do not know if this is where my problem is or not!
Code for WebHostOrder 14 is;

Re: Instance variable inside a method

This code creates an instance of the WebHost class:

WebHost webHost = new WebHost();

The variable: webHost refers to the instance of the class that was created by the new statement.

Is there a reference to an instance of the WebHost class in the WebHostOrder14 class?
Methods in the WebHostOrder14 class must have a reference to the WebHost class to access its methods and variables.

Re: Instance variable inside a method

These very basic concepts seem to be past your current knowledge. I suggest you work with a small program to learn how to create instances of classes and access their methods and variables. Work with something small and simple until you learn how things work, before trying to work with this much larger program.