You are on page 1of 3

Methods (copy for students)

TABLA DE IDENTIFICACIÓN DE LA TAREA

IDIOMA Inglés

ÁREA O MATERIA Programación de Lenguajes

NÚCLEO TEMÁTICO Java. Methods

CORRESPONDENCIA CURRICULAR Ciclo Superior en Desarrollo de Aplicaciones Web

AUTORÍA Antonio Jesús Calvo Morales

TEMPORALIZACIÓN APROXIMADA 2 sesiones de 1 hora

COMPETENCIAS BÁSICAS  Writing methods


 Scope of variables
 Invocation, call or execution of a method
 Overloading

1) Let’s watch a video.


We are going to watch a video. Don't worry if you don't understand
everything, just relax and enjoy!
https://www.youtube.com/watch?v=7MBgaF8wXls

2)According to the video, answer the following question:

What’s an argument in a method?


Any information that the method need in order to work.
Which class is imported above the class “apples”?
Java.util.scanner.
What’s wrong in the name of the classes?
It have to start in capital letter.
Do you remember the name written by keyboard?
Bucky Roberts.
Do you know which the tutorial number is?
15th.
Which was the name of the executable class?
apples.java is the name of the executable class.
Which the method used for printing on the screen? Is it a static
method? Why?
The method used is println(hello + name). No, because is automatically created by java.
Do you remember which the prompt to user was?
Enter your name here.
Is the method simpleMessage(String name) static? Why?
No, because you don’t have to invoke by its class.
No, because is it invoked through the objectTuna.

3) Compare
Compare your answers with your partner. You can use
expressions like:

As far as I’m concerned.


In my opinion.
I agree/disagree with you.
Personally, I think.
I’d say that.
I’d suggest that.
I'd like to point out that.
What I mean is.

4) Identifying method features


Read the following text. Underline the words you don't understand.
Compare your words with your partner and ask the meaning of the
unknown words.

Scope of Declarations
You have seen declarations of various Java entities, such as classes, methods, variables and parameters.
Declarations introduce names that can be used to refer to such Java entities. The scope of a declaration is
the portion of the program that can refer to the declared entity by its name. Such an entity is said to be “in
scope” for that portion of the program.

The basic scope rules are as follows:


1. The scope of a parameter declaration is the body of the method in which the declaration appears.
2. The scope of a local-variable declaration is from the point at which the declaration appears to the end
of that block.
3. The scope of a local-variable declaration that appears in the initialization section of a for statement’s
header is the body of the for statement and the other expressions in the header.
4. The scope of a method or field of a class is the entire body of the class. This enables non-static
methods of a class to use the class’s fields and other methods.

Method Overloading
Methods of the same name can be declared in the same class, as long as they have different sets of
parameters (determined by the number, types and order of the parameters) — this is called method
overloading. When an overloaded method is called, the Java compiler selects the appropriate method by
examining the number, types and order of the arguments in the call. Method overloading is commonly used
to create several methods with the same name that perform the same or similar tasks, but on different types
or different numbers of arguments.

Useful expressions:
What does ______ mean?
I don't understand the meaning of ____. Can you explain it to me?

5) Fill in the blanks in each of the following statements:

a) A method is invoked with a(n)___________ “call method”.

b) A variable known only within the method in which it is declared


is called a(n)____________ “local variable”

c) The ____________ “return” statement in a called method can be


used to pass the value of an expression back to the calling
method.

d) The keyword _________ “void” indicates that a method does not


return a value.

e) Data can be added or removed only from the _________ “setter”


of a stack.
6) Give the method header for each of the following methods:

a) Method hypotenuse, which takes two double-precision arguments


side1 and side2 and returns a double-precision.
“public double hypotenuse (double, double)”
b) Method smallest, which takes three integers x, y and z and
returns an integer.
“public int smallest (int x, int y, int z)”
c) Method instructions, which does not take any arguments and does
not return a value.
“public void instructions()”
[Note: Such methods are commonly used to display instructions to a
user.]
d) Method intToFloat, which takes an integer argument number and
returns a floating-point result.
“public float intToFloat (int)”

Compare your answers with your partner.

You might also like