|
Mr. Rogers AP Computer Science A - Second Quarter Objectives |
| Syllabus | 1st Quarter | 2nd Quarter | 3rd Quarter | 4th Quarter |
|
(AP Computer Science Standard: III Program Analysis)
| Essential Question: How does an algorithm compare to a mathematical model in physics or engineering? |
So, what makes computer algorithms special as compared to say mathematical algorithms? Computer algorithms can do massive numbers of iterations in very short periods of time, enabling new forms of problem solving.
- items numbered
- method for accessing the i th item is defined
- sequential: examines each item in a list in order until it finds the one it's searching for. O(n) run time increases proportional to the number of items searched = n.
- binary: list must be sorted. Uses a divide and conquer technique (20 questions). O(log n) run time increases proportional to the logrithm of the number of items searched, where ( items searched ) = n.
n 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 log n 0.30 0.48 0.60 0.70 0.78 0.85 0.90 0.95 1.00
| Essential Question: What is recursion, recursion, recursion, recursion... ? |
Must have a means of stopping itself based on the modified argument(s)
Stores calculated values in a stack and evaluates them after the recursion stops. uses last-in-first-out (LIFO).
Determine the number of iterations a given recursion will have.
|
Reading Homefun:
Homefun (summative/formative assessment):
|
| Essential Question: What's the difference between style and syntax? |
Chap. 5: Java Syntax and Style
(AP Computer Science Standard: II Program Implementation, III Program Analysis)
Correctly use the three forms of comments:
// Single line comment
/* One or more lines of comments*/
/** Javadoc comments*/
Identify reserved words (p. 107).
Distinguish between syntax and style.
syntax: is the defined form the source code must have. Improper syntax will prevent a program from compiling.
style: is the recognized form source code should take to be easily read and understood by other programmers. Improper form wil not prevent a program from compiling.
Correctly use the naming conventions for classes, methods, and fields.
Capitalize the first letter of classes and constructors but not libraries, packages, methods, fields, or variables.
The first character must be a letter & have no spaces in it.
Names can include letters, numbers or the underscore_.
Names should be descriptive.
Method names = verbs, field = nouns
Symbolic constants use all capitals. example: Math.PI , PI is a public symbolic constant that's a field in the Math class.
Correctly indent programs. All code that belongs inside a set of curly brackets should be indented. Henceforth, deductions will be made for improper indentation. Correct indentation is a style issue.
example:
public class stuff {
public static void main ( ) {
for ( int x = 0 ; x < 12 ; x++ ) {
if ( x == 12 ) {
// some code
- }
}
}
}
- Homefun (summative/formative assessment):
- Read Chap. 5; Princeton professor foresees computer science revolution
- Exercises 3, 4, 5, 7, 8, 10
- Programming Assignment: Lab 5.6
Relevance: A program won't run without proper syntax. Proper style makes the code readable so that it can be modified and maintained.
| Essential Question: How is an expression in a programming language different from the same expression in algebra? |
Chapter 6: Data Types, Variables, and Arithmetic
(AP Computer Science Standard: II Program Implementation, III Program Analysis)
Relevance of the chapter: H Computers do not handle numbers in the same way that algebra does. These differences can cause serious errors or enable new possibilities. An understanding of these differences can be critical in many real-world situations.
Understand the meaning and use of the equal sign in Java.
Can have only one field or variable on the left side
Means "replaced by", not equals
Correctly declare fields, class variables, and local variables or instances.
Fields: Declared inside a class but NOT inside a method. CANNOT be static
Class Variables: Declared inside a class but NOT inside a method. MUST be static.
Local Variables or instances : Declared inside a method.
Correctly initialize (set starting values for) fields, class variables, and local variables or instances.
Fields and class variables: Usually initialized by constructors.
Local variables or instances: Can only be initialized locally
State the default values used for initializing fields or class variables. Note that these are created inside of a class but not inside of a method.
Numeric types: 0
Objects or instances: null
State the default value used for initializing local variables. (Local variable are created inside of methods. There is no default value for local variables.)
State the eight types of primitive data types and their sizes in bytes. (p. 129)
Data Type Size (Bytes) Values boolean 1 true or false char 2 Unicode characters byte 1 very short integer short 2 short integer int 4 integer long 8 large sized integer float 4 floating point (number with decimal) double 8 larger floating point
Explain why the largest size of an integer or long variable can be a major issue. The size is finite and if the size is exceeded the program will not work.
Data Type Max size int from - 2.1 x 10 9 to 2.1 x 10 9 -1 long from - 9.2 x 10 18 to 9.2 x 10 18 -1 float from - 3.4 x 10 38 to 3.4 x 10 38 double from - 1.8 x 10 308 to 1.8 x 10 308
Explain the limitations of precision on floating point data types (float or double) and why these limitations can produce round-off errors. Byte, short, integer, or long have size limitations but are exact numbers, On the other hand, floating point numbers are often not exact. They have a limited number of significant figures, which can be less than the number of decimal places. For example: a number as large as 1.8 x 10 308 would not have 308 significant figures.
Repetitive calculations can produce significant rounding errors. Click here for an example of code that produces significant rounding errors.
State the primitive data types which do not have a true zero and explain why this can be a problem. double and float. These are stored as base 2 logarithms and there is no logarithm for zero.
Correctly Use:
literal constant - letters in single quotes and numbers.
examples: 'a', 2, 37.5, 'D', 42.005
symbolic constant - declared and initialized using final.
example: final int XXX = 5;
escape sequences (used when outputting Strings. See p.131)
examples of escape sequences
escape sequence
effect
\n creates a new line \t creates a tab \\ outputs \ \" outputs " code example: System.out.print ( "Using \"escape sequences\" \n is fun!" ) ;
| Essential Question: When does a variable cease to exist? |
Scope
Understand the term scope (p. 133). Note: the concept of scope is incredibly important to programming in Java. You must consider it whenever you create a variable. As a matter of style, variables should be declared at the top limit of their scope. Click here for an example of scope.
inside the { } of a class
inside the { } of a method
inside the { } of a loop, if, else statement, or any other set of {}
Correctly convert numbers and objects into strings and explain why objects need special attention. (An object may have multiple variables or fields of different data types associated with them, hence the output has to be defined in order to understand how it should be done.)
Concatenate to an empty string. Example: System.out.print ("" + 6);
Use toString method for converting objects to strings By default, the toString method outputs an object's class name and memory location. To output something more meaningful the method has to be overridden or in other words, redefined in the object's class (see toStringDemo at right).
Homefun (summative/formative assessment): read Sections 6.1 to 6.5; Exercises 1- 7 p.146-147
| Essential Question: Is 1/2 the same thing as 1.0 / 2.0? |
Integer Math, Autoboxing and Type Casting
Use literal constants as either int or doubles (Example: int: 2, double: 2.0).
Correctly use the order of operation for arithmetic.
parentheses
division, multiplication, modulus
addition, subtraction
Perform division using integers and doubles.
Integer division truncates the decimal portion of a number. It does NOT round numbers. Mixed division of integers and doubles upgrades the answer to a double (this is called autoboxing).
Examples: division of integers: 1 / 2 yields 0 division of doubles: 1.0 / 2.0 yields 0.5 mixed division: 1 / 2.0 yields 0.5, 1.0 / 2 yields 0.5
Depending on autoboxing can cause unexpected problems due to order of operation. If you don't want to truncate decimals and do want a double then use double literal constants!
Examples: int & double literal constants: 1 / 2 * 2.0 yields 0 1.0 / 2 * 2 yields 1.0
1 / 2.0 * 2 yields 1.0 only double literal constants: 1.0 / 2.0 * 2.0 yields 1.0
Cast variables. This temporarily changes the data type of a variable.
- Example:
- int a = 2, b = 5;
- double c;
- c = ( double ) a / b ; // c has a value of 0.4 . The variable a is temporarily
- // type cast as a double causing b to be autoboxed as a double.
- c = a / b ; // c now has a value of 0.0 . Although a was type cast as a
- // double, it returns to being an integer if no longer type cast.
- c = ( double ) ( a / b ) ; // c has a value of 0.0 . Due to order of operation,
- // a/b occurs before the type casting to double.
Truncate and round numbers using integer division.
- Examples:
- Normal Rounding:
- 0.5 rounded to nearest whole number
- roundedValue = ( (int) ( 0.5*10 ) + 5 ) / 10 ; // yields 1
- x rounded to nearest whole number
- roundedValue = ( (int) ( x*10 ) + 5 ) / 10 ; // assumes x & y are int
Rounding Upward--When billing customers, rounding tenths of cents upward can result in millions of dollars of extra profit.
0.1 rounds tenths upward to nearest whole number roundedValue = ( ( int ) ( 1*10 ) + 9 ) / 10 ; // yields 1
x rounds tenths upward to nearest whole number roundedValue = ( ( int ) ( x * 10 ) + 9 ) / 10 ; // assumes x & y are int
Rounding downward--When paying debts, rounding tenths of cents downward can result in millions of dollars of extra profit.
0.9 rounds all decimal places downward (truncates) roundedValue = (int) (0.9 * 10 ) / 10 ; // yields 0
x rounded to nearest whole number roundedValue = (int) ( x * 10 ) / 10 ; // assumes x & y are int Relevance: Handling massive numbers of transactions involving money without losing any funds due to rounding errors is a major issue for international finance and businesses.
Characters are stored as integers and can be used to perform integer math. (See example code.)
summative/formative assessment (in class): Create 10 practice problems using integer math, order of operation and type casting. Trade with a partner and work the practice problems on paper. Run the code and check your answers.
Modulus Math
|
||||||
|
|
|||||
example:int offSwitch, x, offPoint = 5 ;offSwitch = ( x % offPoint ) / x ; // Try evaluating this code for values// of x from 1 to 10
Programming Assignment--Shapes Program: Write a program which uses command line input to input a single dimension in centimeters. Use this dimension to calculate and output the surface area and volume of a cube, sphere, and cylinder along with the correct units. The radius and height of the cylinder are equal to the dimension that was input. Use a separate method for each calculation.
| Essential Question: How does a progressive income tax system work and is it a good idea? |
Note: with a progressive income tax, when a higher rate is triggered the taxpayer only pays the higher rate on income above the amount that triggers the higher rate.
Tax code program: Modify the code provided so that it meets the following specifications:
Input: income in dollars.
Output:
Taxable income in dollars (show only 2 decimal places).
Tax due in dollars (round tenths of cents upward and show only 2 decimal places).
Nominal tax rate in % of income (show only 1 decimal places).
NTR = (taxDue) / (income) *100
Description: The program will round any tenths of a cent upward. "If" statements are not allowed. The program will use only algorithms to calculate taxes. It will use the following progressive tax table:
| Income ($) | Tax Rate | Comments |
| 0 to 19,999.99 | 00 % |
This part of income is never taxed |
| 20,000 to 29,999.99 | 25 % | Only income above $19,999.99 is taxed at 25% |
| 30,000 + | 35 % | Only Income above $29,999.99 is taxed at 35%. Note this is an additional 10% above the 25% tax that kicks in at $29,999.99. |
| Homefun (summative/formative assessment): |
|
Summative Assessment: Test Chap 5 & 6 Objectives 1-24
| Essential Question: Do we live in a binary world? |
Chapter 7: Boolean Expressions and Conditional Control
Define conditional control.
Correctly use both if and if-else statements. (Be as one with the four Common if-else Errors on p. 156.)
Draw flowcharts for both if and if-else statements.
Correctly use boolean relational operators. == , > , < , >= , <= , !=
Correctly use boolean logical operators. && , || , !
Given a set of logic gates write the associated boolean expression (p. 3).
Write truth tables for "and", "or", and "xor" gates.
Evaluate complex boolean statements using correct order of operators (p. 163).
Highest ^ ^ ^ ^ Lowest
! (unary) - (cast) ++ -- * / % + - == < <= > >= != && ||
Correctly describe and use short-circuit evaluation.
Correctly use if-else-if tables for menus and selection processes like tax tables (see example code)
Correctly use switch statements. (Be as one with the six points on p. 197)
Summative Assessment : Test Chap 11 Objectives 1-11
| Essential Question: How can we access and perform similar manipulations on millions of volatile pieces of similar information without having to create millions of lines of code? |
Chapter 8 Iterative Statements (Loops)
Relevance: Many if not most algorithms require loops. Loops are basic to all forms of computer science.
- initialization
- testing
- incrementing
Note, that for-loops, while-loops, and do-while loops can all perform the same tasks. the choice of loop type is ultimately a matter of programming style. (example code)
Loop Type
Example Comments for
- int x;
- for (x = 0; x < n; x++) {
- ... code
- }
Used when the number of times the loop needs to run is known
while
- int x = 0;
- while (x < n) {
- x++;
- ... code
- }
Used when the number of times the loop needs to run is not known
do...while
- int x = 0;
- do {
- x++;
- ... code
- } while (x < n);
Used when the number of times the loop needs to run is not known but must be at least once.
foreach
- double y [ ] = new double [n];
- for (double i: y) {
... code
}Always runs exactly n times where n = size of list. Starts at list index of 0 and increments upwards by one
return: ends both the loop and the method (or causes the method to rerun itself in the case of recursion).
break: ends the loop it is contained in. With nested loops if the break statement is in the innermost loop it will end only that loop.
- even/odd numbers
- factorials
- fibonacci numbers
|
Homefun
(summative/formative assessment):
|
Programming Assignment (summative/formative assessment):
- Lab 8.6; Exercise 10, 11, 12
Summative Assessment: Test Chap 8 Objectives 1-12
| Essential Question: How can we store and manipulate not just numbers but human text in a computer program? |
Chap. 10 Strings
- String ( )
- String ( String s )
- String s1 = " "; // s1 is set to an empty String
- String s2 = new String(); // s2 is set to an empty String
- String s3; // s3 is set to null
- length ( )
- charAt ( pos ) // Note that characters are counted starting at 0.
- substring ( pos )
- substring ( fromPos, toPos )
- compareTo ( s2 ) // returns neg int if s1 <s2, 0 if s1 = s2, pos int if s1>s2
- compareToIgnoreCase ( s2 ) //returns neg int if s1 <s2, 0 if s1 = s2, pos int if s1>s2 ignoring case
- equals( s2 ) // returns a boolean true or false
- equalsIgnoreCase ( s2 ) // returns a boolean true or false ignoring case
- indexOf ( ch ) // four types
- lastIndexOf ( ch ) // four types
- trim ( ) // removes white space characters from beginning and end of string
- replace ( oldChar, newChar )
- toUpperCase ( )
- toLowerCase ( )
See example code VowelFinder
- yourString += str;
- yourString = yourString1 + str;
- yourString.concat (str);
- s1.equals ( s2 )
- s1.equalsIgnoreCase ( s2 )
- s1.compareTo ( s2 ) methods
- s1.compareToIgnoreCase ( s2 )
examples:
int yourInteger = Integer.parseInt ( yourString ) ;
String yourString = String.valueOf ( yourNumber ) ;
|
|
|
|
|
|
Homefun (summative/formative assessment):
- inputs 2 strings using command line input.
- Output the length of both strings, the 3rd character in both strings.
- Test the strings to see if they are the same and output whether they are. Concatenate the two strings and output the result.
- Output any capital letters in the concatenated string along with their position.
Summative Assessment: Test Chap 10 Objectives 1-13
| Essential Question: How can we store millions of volatile pieces of similar information without having to create millions of variables in a computer program? |
Chap. 12 Arrays and ArrayLists
- int scores [ ] = new int [5] ;
- int scores [ ] = { 93, 67, 99, 87, 91 } ;
- numbers = 0
- boolean = false
- objects = null
given : int incomes [ ] = new int [ 5 ] ;
example of a method's parameters : someMethod ( int inc [ ] ) ;
example of calling the method : someMethod ( incomes ) ;
Note: the [ ] in the example indicates that an array is being passed to the method. Do not put the size of the array in the brackets. Do not use the [ ] when using an array as an argument. (See example code.)
- final int ROWS = 2;
- final int COLS = 3;
- double name2DArray [ ] [ ] = new double [ROWS] [COLS] ;
- or
- double name2DArray [ ] [ ] =
- {
- {0.0, 2.7, 5.6},
- {4.3, 1.4, 7.2}
- };
- twoDArray.length returns the number of rows
- twoDArray[0].length returns the number of columns
- Name Salary $1000/yr
- Bob Arnold 90
- Herb Bobo 12
- Jane Cool 27
- Alfred Nameless 49
- Juan Smith 200
- Betty Taylor 142
Next, output the total of all salaries. Use a random number generator to fire two employees. Remove them from the Array List then add a new employee called Bob Newguy with a salary of $200,000. Again, output a table with the names of the current employees and their salaries. Also output the total of all salaries.
Note: You need to write the letters on graph paper or in an Excel spread sheet in order to understand how many spaces are needed. To understand how the arrays should be initialized look at chapter 10 objective 7 above. You do not need to reproduce the grid lines in your program's output.
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | |
| 0 | A | ||||||||||
| 1 | A | A | |||||||||
| 2 | A | A | |||||||||
| 3 | A | A | A | A | A | A | A | ||||
| 4 | A | A | |||||||||
| 5 | A | A |
Summative Assessment: Test Chap 12 Objectives 1-16
| Essential Question: How can you succeed on the semester exam? |