So far, we have been writing programs that request information from the computer user and store it in multiple variables and then process the variables to compute specific tasks. As we write more complex programs, we need to store the values provided into a “data base”, primarily because we will need the values eventually to perform additional operations.
In theory: we can use variables for each value we would like to process,
The problem: is that when we may have “a lot” of values, it is almost impossible to define a variable for each value.
Solution: is to define an array of the same data type that will store a specific number of variables in a compact form.
Notice that the loops are the “BBF” (Best Friend Forever) of the arrays. Mainly because most of the time, your programs will have to navigate through the array either to print, process data, find, add or remove data. Every time these operations are performed, then you need to start from position 0 (int i = 0), all the way until you reach the end of the array (i < array.length), and you need to process the subscripts one-by-one (i++). The body of the loop will depend on whatever the task is in the first place. But the skeleton will always be the same:
for(int i =0; i < array.length; i++){
// body of the loop
}
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.
[while Loop]
CON-2.H Compute statement execution counts and informal run-time comparison of iterative statements.
CON-2.H.1 A statement execution count indicates the number of times a statement is executed by the program.
[do-while Loop]
CON-2.C.1 Iteration statements change the flow of control by repeating a set of statements zero or more times until a condition is met.
[Random Numbers]
CON-1.D.4 The values returned from Math.random can be manipulated to produce a random int or double in a defined range
[Accessing and Processing Array Elements]
CON-2.I For algorithms in the context of a particular specification that requires the use of array traversals— a. Identify standard algorithms b. Modify standard algorithms c. Develop an algorithm;
VAR-2.C.1 An enhanced for loop header includes a variable, referred to as the enhanced for loop variable.
VAR-2.C.2 For each iteration of the enhanced for loop, the enhanced for loop variable is assigned a copy of an element without using its index.
VAR-2.C.3 Assigning a new value to the enhanced for loop variable does not change the value stored in the array.
VAR-2.C.4 Program code written using an enhanced for loop to traverse and access elements in an array can be rewritten using an indexed for loop or a while loop.
[Array Operations]
CON-2.I.1 There are standard algorithms that utilize array traversals to— ● Determine a minimum or maximum value ● Compute a sum, average, or mode ● Determine if at least one element has a particular property ● Determine if all elements have a particular property ● Access all consecutive pairs of elements ● Determine the presence or absence of duplicate elements ● Determine the number of elements meeting specific criteria
CON-2.I.2 There are standard array algorithms that utilize traversals to— ● Shift or rotate elements left or right ● Reverse the order of the elements
ACM CCECC
[Using Methods]
SDF-14. Analyze programming code that utilizes preconditions, postconditions, and invariants.
Explain the importance of algorithms in the problem-solving process.
Demonstrate how a problem may be solved by multiple algorithms, each with different properties.
Read a given program, and explain what it does
Trace the flow of control during the execution of a program (both correct and incorrect).
Use appropriate terminology to identity elements of a program (e.g., identifier, operator, operand)
Reading and explaining code
Basic concepts such as variables, primitive data types, expression evaluation, assignment, etc.
Apply basic programming style guidelines to aid readability of programs such as comments, indentation, proper naming of variables, etc.
Basic testing (perhaps using suitable frameworks) including test case design
Basic concepts such as variables, primitive data types, expression evaluation, assignment, etc.
Key modularity constructs such as functions (and methods and classes, if supported in the language) and related concepts like parameter passing, scope, abstraction, data encapsulation, etc.
When and how to use standard data structures
Structured data types available in the chosen programming language like sequences (e.g., arrays, lists), associative containers (e.g., dictionaries, maps), others (e.g., sets, tuples) and when and how to use them.