|
How to use Methods in Java Methods and Parameters in Java Creating User-Defined Methods Common Programming Errors Good Programming Practices Lab Exercises Labs 1 Labs 2 Rubric
| |
Defining Our Own
Subroutines
| Unit 3 |
Activity 3 |
Time:
320
minutes
|
Description
This
activity builds on students’ knowledge of variables and subroutines. Through a
series of discussions, demonstrations, and lab exercises, students learn to make
the distinction between local and global variables as they relate to variable
parameters in programmer-defined subroutines.
Strand(s) & Learning
Expectations
Strand(s):
A. Programming Concepts
and Skills
B. Software Development
C. Computer Environments and Systems
D. Topics
in Computer Science
|
Overall Expectations
|
| A1. |
demonstrate the ability to use different data types, including
one-dimensional arrays, in computer programs; |
| A2. |
demonstrate the ability to use control structures and simple
algorithms in computer programs; |
| A3. |
demonstrate the ability to use subprograms within computer programs; |
| A4. |
use proper code maintenance techniques and conventions when creating
computer programs. |
| B1. |
use a variety of problem-solving strategies to solve different types
of problems independently and as part of a team; |
| B2. |
design software solutions to meet a variety of challenges; |
| B3. |
design algorithms according to specifications; |
|
Specific Expectations
|
| A1.1 |
use constants and variables, including integers, floating
points, strings, and Boolean values, correctly in computer
programs; |
| A1.3 |
use assignment statements correctly with both arithmetic and
string expressions in computer programs; |
| A1.4 |
demonstrate the ability to use Boolean operators (e.g., AND,
OR, NOT), comparison operators (i.e., equal to, not equal to,
greater than, less than, greater than or equal to, less than or
equal to), arithmetic operators (e.g., addition, subtraction,
multiplication, division, exponentiation, parentheses), and
order of operations correctly in computer programs; |
| A2.1 |
write programs that incorporate user input, processing, and
screen output; |
| A2.2 |
use sequence, selection, and repetition control structures
to create programming solutions; |
| A2.3 |
write algorithms with nested structures (e.g., to count
elements in an array, calculate a total, find highest or lowest
value, or perform a linear search). |
| A3.1 |
demonstrate the ability to use existing subprograms (e.g.,
random number generator, substring, absolute value) within
computer programs; |
| A3.2 |
write subprograms (e.g., functions, procedures) that use
parameter passing and appropriate variable scope (e.g., local,
global), to perform tasks within programs. |
| A4.1 |
demonstrate the ability to identify and correct syntax,
logic, and run-time errors in computer programs; |
| A4.2 |
use workplace and professional conventions (e.g., naming,
indenting, commenting) correctly to write programs and internal
documentation; |
| A4.3 |
demonstrate the ability to interpret error messages
displayed by programming tools (e.g., compiler, debugging tool),
at different times during the software development process
(e.g., writing, compilation, testing); |
| A4.4 |
use a tracing technique to understand program flow and to
identify and correct logic and run-time errors in computer
programs; |
| A4.5 |
demonstrate the ability to validate a program using a full
range of test cases. |
| B1.1 |
use various problem-solving strategies (e.g., stepwise
refinement, divide and conquer, working backwards, examples,
extreme cases, tables and charts, trial and error) when solving
different types of problems; |
| B1.2 |
demonstrate the ability to solve problems independently and
as part of a team; |
| B1.3 |
use the input-process-output model to solve problems. |
| B2.1 |
design programs from a program template or skeleton (e.g.,
teacher-supplied skeleton, Help facility code snippet); |
| B2.2 |
use appropriate vocabulary and mode of expression (i.e.,
written, oral, diagrammatic) to describe alternative program
designs, and to explain the structure of a program; |
| B2.3 |
apply the principle of modularity to design reusable code
(e.g., subprograms, classes) in computer programs; |
| B3.1 |
design simple algorithms (e.g., add data to a sorted array,
delete a datum from the middle of an array) according to
specifications; |
| B3.2 |
solve common problems (e.g., calculation of hypotenuse,
determination of primes, calculation of area and circumference)
by applying mathematical equations or formulas in an algorithm; |
| B3.3 |
design algorithms to detect, intercept, and handle
exceptions (e.g., division by zero, roots of negatives). |
| B4.4 |
use a test plan to test programs (i.e., identify test
scenarios, identify suitable input data, calculate expected
outcomes, record actual outcomes, and conclude ‘pass’ or ‘fail’)
by comparing expected to actual outcomes; |
| B4.5 |
use a variety of methods to debug programs (e.g., manual
code tracing, extra code to output the state of variables); |
Planning Notes
-
Gather
samples of built-in subroutines for identification of functions vs.
procedures and for identification of parameters.
-
Provide
and demonstrate syntax required for writing programmer-defined subroutines
in the language of choice.
-
Provide
on-line and/or print resources for shared use by students.
-
Provide
examples that help students understand variable scope and the passing of
parameters as information to parts of the program. Students often have
difficulty with variable scope and parameter passing.
-
Review
variable naming conventions and/or adopt conventions that identify the scope
of a variable.
Prior Knowledge &
Skills
Students:
Teaching/Learning
Strategies
|
e.g.,
|
in
order for the sqrt function to produce the desired result, a number (parameter)
must first be passed
to the sqr subroutine:
sqrt(36)
|
|
|
and
a value is returned:
|
6
|
-
Assign students
the task of identifying the required parameters for a series of selected
functions and procedures, making connections to math and text subroutines
explored in Activities 2 and 3.
-
Discuss the
concept of variable scope and the need for parameters to pass information from
one component to another.
-
Facilitate a
brainstorming session to write an algorithm for a modular program that reads
(input) a customer’s bank balance
then, if the balance is less than zero, prints an “Overdraft” notice, or
else interest is calculated (based on
current rate) and added to the
original balance.
-
Promote use of
subroutines to divide tasks, identifying required parameters for each
subroutine.
-
Introduce the
concept that the parameters for balance
and interest are considered variable
parameters because their values are changed by the Calculate subroutine, while
the rate parameter is not a variable
parameter because its value is not changed by the Calculate subroutine.
-
Demonstrate the
syntax for defining a custom subroutine in your programming language.
-
Student record
new tools and strategies in a journal or notes.
-
Student
complete as many lab exercises as possible in time allotted. (See
Lab Exercises, Labs
1, Labs 2)
Assessment & Evaluation of Student Learning
As Learning
Students will be given time to:
- reflect on their progress/
understanding/areas of concern
based on teacher/student/peer
suggestions (e.g. after test take up)
- journalize their reflections
- reflect on the work of others
For Learning
The teacher will
- observe student progress/performance
- ask questions based on student work
- check homework correctness/completion when appropriate
- review formative quiz results
Of LearningThe
teacher and students gather assessment information based on specific
expectations outlined for this activity, including:
-
a formative
assessment of the assigned work in the form of roving conferences;
-
a formative
assessment of the journal/notebook (checking for inclusion of tools/strategies
presented);
-
a
summative
assessment of the student’s ability to describe parameter passing and scope
and identify differences between local and global variables. Students break down
computer tasks into specific functions and define the modules, parameters, and
variables used.
Accommodations
The
following are ways in which the activity can be adapted to accommodate the
exceptional students’ needs:
-
support
brainstorming activity through use of web or mapping chart with print copy;
-
provide support
through one-to-one teacher-directed conferencing to ensure understanding;
-
provide
“scaffolded” programs (program listings with subroutine headings, loop
structures, etc., already included) to help struggling students.
Resources
Source:
Public
and
Catholic
District School Board Writing
Partnership,
Course
Profile: Computer
and Information Science,
Grade 11, University/College
Preparation ICS3U,
Queen’s Printer for Ontario, 2001, adapted.
|