Description: Introduction to the fundamentals of methods, their definition, and calling. Common uses of methods are creating more readable programs, enhancing debugging, creating reusable code, and many more.
Code:
ACM CCECC
N/A
AP CS A
[Defining and Calling a Method]
MOD-1.E.4 A method or constructor call interrupts the sequential execution of statements, causing the program to first execute the statements in the method or constructor before continuing. Once the last statement in the method or constructor has been executed or a return statement is executed, the flow of control is returned to the point immediately following where the method or constructor was called.
MOD-1.F.1 A method signature for a method with parameters consists of the method name and the ordered list of parameter types.
MOD-1.F.2 Values provided in the parameter list need to correspond to the order and type in the method signature.
[Using Methods]
VAR-1.G.4 Through method decomposition, a programmer breaks down a large problem into smaller subproblems by creating methods to solve each individual subproblem.
[Passing Arguments to a Method and Local Variables]
VAR-1.G.3 Formal parameters and variables declared in a method or constructor can only be used within that method or constructor.
VAR-1.G.1 Local variables can be declared in the body of constructors and methods. These variables may only be used within the constructor or method and cannot be declared to be public or private.
CS1
[Using Methods]
130.421.c.4.a Use program design problem-solving strategies to create program solutions;
130.421.c.4.c Identify the subtasks needed to solve a problem;
130.421.c.4.e Identify reusable components from existing code;
Description: In this session, the technique of divide and conquer is explained and used to address problems and give solutions. Methods are essential in the accomplishment of the introduced technique.
Code:
ACM CCECC
N/A
AP CS A
[Defining and Calling a Method]
MOD-1.E.3 A method signature for a method without parameters consists of the method name and an empty parameter list.
MOD-1.G Call non-static non-void methods with or without parameters.
[Returning a Value from the Method]
MOD-1.G.1 Non-void methods return a value that is the same type as the return type in the signature. To use the return value when calling a non-void method, it must be stored in a variable or used as part of an expression.
MOD-1.E.7 Void methods do not have return values and are therefore not called as part of an expression.
CS1
[Using Methods]
130.421.c.6.h Create subroutines that do not return values with and without the use of arguments and parameters;
[Passing Arguments to a Methods and Local Variables]
130.421.c.6.j Understand and identify the data-binding process between arguments and parameters;
130.421.c.6.f Use local and global scope access variable declarations;
[Returning a Value from a Method]
130.421.c.6.i Create subroutines that return typed values with and without the use of arguments and parameters;
Description: Given a number from the computer user, recognize if it is prime. If it is a prime, display, the number is prime. Otherwise, perform an operation.
ACM CCECC
[Using Methods]
SDF-14. Analyze programming code that utilizes preconditions, postconditions, and invariants.
AP CS A
[Using Methods]
MOD-2.C.3 A precondition is a condition that must be true just prior to the execution of a section of program code in order for the method to behave as expected. There is no expectation that the method will check to ensure preconditions are satisfied.
MOD-2.C.4 A postcondition is a condition that must always be true after the execution of a section of program code. Postconditions describe the outcome of the execution in terms of what is being returned or the state of an object.
MOD-2.C.5 Programmers write method code to satisfy the postconditions when preconditions are met.
[Documentation Comments]
MOD-2.C.3 A precondition is a condition that must be true just prior to the execution of a section of program code in order for the method to behave as expected. There is no expectation that the method will check to ensure preconditions are satisfied.
MOD-2.C.4 A postcondition is a condition that must always be true after the execution of a section of program code. Postconditions describe the outcome of the execution in terms of what is being returned or the state of an object.
MOD-2.C.5 Programmers write method code to satisfy the postconditions when preconditions are met.
CS1
N/A