Chapter 7 Flashcards

0
Q

What is a user-defined method

A

Methods created by the user.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

What is a pre-defined method.

A

Methods already created for use.

Examples: Println; printf; showInputDialog

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Advantages of user defined method.

A
  1. Allows you to reuse methods many times
  2. Different people can work on different methods in the program simultaneously
  3. Allows user to focus on one part of the program at a time.
  4. Enhances readability of a program; reduces amount of code in program.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the various pre-defined methods used to separate a person’s first and last name?

A
  1. length
  2. indexOf
  3. subString
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the pre-defined method, length?

A

Tells you the number of characters in a given string.

strLen = name.length( );

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the pre-defined method, indexOf?

A

Returns the location of the parameters entered into the method.

Example: we use a “space” when separating first and last names

spaceLoc = name.indexOf(“_”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the pre-defined method substring?

A

Extracts a string from within a string

Example:
firstName = name.substring(0,spaceLoc)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does one know what pre-defined methods exist and how to use them?

A

Using a programming textbook or class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What info must you know about a predefined method in order to use it.

A
  1. name of the method
  2. The parameters that are required to use it.
  3. The method type (what the method will return)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Define the term parameters.

A

Listed after the method name in parentheses. Determines the output. Need to list parameters in the order that it is defined in the method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Define the term method type.

A

The return type given from a method.

Data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

List methods’ return types and number of parameters.

A
  1. length returns an int data type, and has no parameters.
  2. indexOf returns int, and has 1 parameter.
  3. substring returns a String, and has 2 parameters.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

List and describe the 2 types of user defined methods.

A
  1. Value returning: must do something with the returned value.
  2. Void: does not return a value.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

List and describe the 2 parts of a method definition.

A
  1. Heading: lists return type, name of the method, the number and data of parameters.
  2. Body: gives code to accomplish the task performed by the method.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Give an example of a method definition.

A

modifier(s) returnType methodName (formal parameter list)

{
//code for method. Tasks performed here.
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Define formal parameters.

A

The variables declared in the heading, within parentheses.

16
Q

Define Actual Parameters.

A

The variables or expressions used in a call to a method.

17
Q

What modifier is used for the methods we used in class?

A

We used Static and final.

But here are some more:

private, public, abstract, protected.

18
Q

Be able to code a simple method, similar to what was created in class.

A

Look at program for this.

19
Q

How many formal parameters can a method have?

A

0 or more.

20
Q

What statement is used to return a value from a method?

A

return ____;

The blank could be a calculation, variable name, or literal name.

21
Q

Be able to call a method in from main

A

Look at programs.

22
Q

Is a literal value or expression allowed to be used as an actual parameter?

A

Can’t find info on this question.