(AP Computer Science Standard: III Program Analysis)
Essential Question: How does an algorithm compare to a mathematical model in physics or engineering? |
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.
Programming Assignment: Write a program that inputs an integer n using command line input and uses it to calculate n factorial using recursion.
- Programming Assignment: Write an application that finds and outputs Pi using recursion and the following series: Click here for 3 examples of recursion.
(Pi 2)/6 = 1 + 1/22 + 1/32 + ... + 1/n2
Input the number of times the recursion should run using command line input.
- 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 = 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'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).
Correctly use the naming conventions for classes, methods, and fields.
Capitalize the first letter of classes but not methods or fields.
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
Constants use all capitals.
Correctly indent programs.
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: Why did you learn to find remainders in grade school instead of going straight to long division ? |
Chapter 6: Data Types, Variables, and Arithmetic
(AP Computer Science Standard: II Program Implementation, III Program Analysis)
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 and local variables.
Correctly initialize fields, local variable, and parameters.
State the default values used for initializing fields.
numeric types: 0
objects: null
State the default value used for initializing local variables. (there isn't one)
State the eight types of primitive data types and their sizes in bytes. (p. 129)
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 slightly over 2.1 x 10 9 long slightly over 9.2 x 10 18 double 1.8 x 10 308
Explain the limitations of precision on floating point data types and why these limitations can produce round-off errors. Unlike a short, integer, or long, a floating point number is not exact. It has a limited number of significant figures. Repetitive calculations can produce 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
Correctly Use:
literal constant - letters in single quotes and numbers
symbolic constant - declared and initialized using final
escape sequences (p.131, \n newline, \t tab, \\ slash, etc.)
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.
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 (This method outputs the class name and memory location. To output something more meaningful it has to be overridden.)
Homefun (summative/formative assessment): read Sections 6.1 to 6.5; Exercises 1- 7 p.146-147
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.
Note: 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
Truncate and round numbers using integer division.
- Examples:
- 1/2 rounded to nearest whole number
- ((1*10) / 2 + 5) / 10 yields 1
- y/x rounded to nearest whole number
- ((y*10) / x + 5) / 10
Cast variables.
- Example:
- int a, b;
- double c;
- c = (double) a / (double) b;
|
|
Programming Assignment: 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. Use a separate method for each calculation.
Relevance: Handling massive numbers of transactions involving money without losing anything to rounding errors is a major issue for international finance and businesses.
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:
Input: Using the command line input income in dollars. (This needs to be changed to cents inside the program.)
Output:
Taxable income in dollars
Tax due in dollars (round tenths of cents upward)
Nominal tax rate in % of income
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-22