Calling your method
A step-by-step guide to calling a method:
1) Look at the method header in the class that holds the method. It
will look something like:
public static double doit(int a, String y)
2) Open the class that you want to call the method. Be sure you are
inside a method (such as main) and then write the method name followed
by (). (Right now, main is often the calling method.) For
example:
doit();
3) Look at the parameters that the method wants. Look at all the
variables available in your calling method. Fill in the requested
parameters with variables of the correct type.
doit(myInt, myString);
4) Look at the return variable. If it is void, skip this step,
otherwise, ask yourself whether you want your calling method to keep
the result of called method. (Right now, if you are not sure, assume
you to keep it.) Put an equal sign before the method and set it equal
to a variable of the return type. For example:
double myDouble = doit(myInt, myString);
5) If the method you are calling is in the same class, you are done. If
it is in another class, you need to tell your method how to reach the
called method. Look for the word static.
If the method you are calling is static:
Put the name of the class before the method name
followed by a dot. ex: double myDouble = Car.doit(myInt, myString);
If the method you are calling is not static:
Put the name of an object of the class before the
method name followed by a dot.
ex: double myDouble = myCar1.doit(myInt, myString);
ex: answer = myScreen.next();
ex: name = name1.toLowerCase();