ap computer science a jacobson week 1 second semester
TRANSCRIPT
AP Computer Science A
Jacobson
Week 1
Second Semester
Agenda
• First Semester- Reflections
• Book Check (For Real)
• Marine Biology Case Study– Chapter 1
• Homework
• First Semester Grades
Objectives for Today
• Today we will reflect upon the strengths and weaknesses of this class last semester, in both a verbal and written form.
• You will also observe, report and analyze the running marine biology case study.
Reflection of First Semester
Fold a piece of paper (that you will turn in) in half “like a hot dog”
On the left, brainstorm all of the positive aspects of last semester.
On the right, brainstorm all of the roadblocks to your learning or things that could be better.
Share with Class
Mr. Jacobson’s Reflections
Positives
Hard work- Diligence
Problem solving skills are starting to show
Semester Project
Mr. Jacobson’s Reflections
Negatives
Mr. Jacobson’s Reflections
Semester Project
Great Job following directions
Needs more work on Object Oriented Programming concepts
Needs more work on algorithms
Battleship tutorial only helped 1 or 2 groups
Mr. Jacobson’s Reflections
Places for Change
More responsive assessments
More student participation
Less “distractions”
Book Check
• Collect all Simply Java
• Check the number of the other textbook
Marine Biology Case Study
• What is the purpose?• Background• Chapters 1-4 in the Acrobat File for our class• Getting it running• Making Observations• Class discussion
Marine Biology Case Study
• Getting it running
Warm up
Assume that x is an initialized int variable. The code segment
if (x>5) x*=2;
if (x>10) x = 0;
Is equivalent to which of the following code segments?
A. x = 0;
B. if (x > 5) x = 0;
C. if (x >5) x*= 2;
D. if (x > 5) x = 0 else x*= 2;
E. if ( x > 5) x *=2; else if (x > 10) x = 0;
Agenda
• Finish Chapter 1 Case Study– Work together– Class discussion
• Truth Tables
Case Study
Objective-Truth tables
Today you will make a truth table for a complex logical expression and apply that to java programming.
Truth Tables
• What data type is either TRUE or FALSE?– boolean
• What types of statement evaluate an expression that is either TRUE or FALSE?– if statements– while loops– For loops
Simple Comparisons
( total == sum )
(x < 20)
( str.charAt(0) != str.charAt(9) )
NOTE: Here total, sum and x could be integers or doubles. “str” is a String and the method charAt() returns a character for comparison.
When there is only one comparison in the whole expression, it is easier to understand
More Complex- Truth tables can help
( (X > 20) && (X < 30) )“&&” statements are true only if both parts are true
A B A &&B
T T T
T F F
F T F
More Complex- Truth tables can help
( (X > 20) | | (X < 30) )“| |” statements are true if one or the other is true
A B A || B
T T T
T F T
F T T
F F F
More Complex- Truth tables can help
( (X > 20) && ! (X < 30) )
A B !B A && !B
T T F F
T F T T
F T F F
F F T F
Make a truth table
Make a truth table for the following expression
!A && !B
A B !A !B !A &&!B
T T F F F
T F F T F
F T T F F
F F T T T
Equivalent Expressions
Two expressions are logically equivalent if their truth tables reveal that the same input results in the same output
! ( A && B) is equivalent to !A | | !B
Where A and B are logical expressions
HW
From Book- p. 177 3.2, 3.3, 3.9, 3.10
Explain your answers in detail. (Hint- Make some type of truth table)
Due at beginning of next class
Warm up
1. Consider writing a program to be used by a restaurant to keep track of the items on the menu, which include appetizers, main dishes and desserts. The restaurant wants to keep track, for every menu item, of the ingredients needed to prepare that item. Some operations will be implemented that apply to all menu itemsm and there will be some specialized
Warm UpConsider the following two methodspublic static void printStuff(int x) {
int y=1;while (y < x) {
System.out.print(y + “ “);y *=2;if (y == x/2) return;}
}public static void mystery( ) {
int x = 8;while (x > 0) {
printStuff(x);x /= 2;
}System.out.println(“x=“ + x);
}
What will be the output when method mystery is called ?
A. 1 2 1 1 1 x=0
B. 1 2 1 1 x=0
C. 1 2 2 x=0
D. 1 2 4 x=8
E. 1 2 x=8
Warm up picture
Mystery
x
printStuff (int x)
x
y
OUTPUT
Agenda
• Warm Up
• Collect HW
• Chapter 4 Review- Group Presentations– Sections 4.0-4.5, 2.6, 2.0– 30 minutes to prepare– 5 minutes or less to present
HW- you may start in class as needed
• P.240 true-false questions
• Provide justification for your answers– Give counterexample if false– Give explanation if true
• Read-Notes 248-255 (Start Chapter 5)
Agenda
• Study Session• Tracing the Code- Continued• static modifier
– static variables– static methods
• HW- p.293 5.1-5.9 T-F Give Explanations• Notes- up to section 5.4
Study Sessions
Tracing the Code
• Where were we last time?
• Parameter Passing Example– Pages 253-255
Agenda 2-17-06
• Collect HW
• Programming Projects p.294 5.1
• Finish the Chapter– interface
• Making one
• Using one
Agenda 2-22-06
• Collect Missing Assignments• Finishing the Chapter- Interfaces• Programming Projects (Due by end of next
class)– P.294 5.2, 5.6, 5.7
• Test Chapter 4-5 (up to 5.4) Tuesday Feb 28th
Time to Imagine…
Imagine a bunch of 4 year olds in the middle of a basketball court
Time to Imagine…
And the adult in charge says “ OK, RUN!!!”What will happen?
Time to Imagine…
Now imagine the same set up with the following exception:
Time to Imagine…
A series of walls are put up. What will the kids do in this case?
In Programming Chaos Should be avoided
• There needs to be some way for programmers to be organized and consistent
• One way this can be accomplished is through a well designed interface.
interface - what is it?
• An interface looks like an “empty” class– All methods are abstract and public
• Headers for methods are listed but not implemented
– An interface has no data members– An interface may have constants
• public static final data
More on interfaces
To use an interface for a class you are creating, you use the keyword “implements”
When a class implements a specific interface, it must create the details for each method that was listed in that interface.
Example
Suppose you wanted to write a Geometry program about shapes. Ultimately, your program will be able to create and measure properties of many shapes, such as circles, squares, trapezoids, and possible a shape you do not know about yet.
Thinking “abstractly” what is something you would want to know about any shape in the program?
“Shapes” interface
You can design a “Shape” interface that would force anyone who introduces a new shape to write code in an organized way.
public interface Shape{public double getArea();public void printCenter();public void makeVisible();}
“Shapes” interface
You can design a “Shape” interface that would force anyone who introduces a new shape to write code in an organized way.
public interface Shape{public double getArea();public void printCenter();public void makeVisible();}
If I implement this interface, I
will have to make at least 3
methods
AP Java Subset
• For the AP-A course, you need to be able to implement the Comparable interface
• It only has one method– Int compareTo( Object obj)
Agenda 2-24-06
• Finish 5.2 - 5.6 - 5.7 Be ready to show me by 8:45
• Test Next Tuesday – Similar format to the quizzes
• Multiple Choice
• Trace the code
• Write a method
• Notes- Power Point posted online
Test Topics
• Chapter 4
• Chapter 5 up to 5.4– Example of Parameter Passing
• Objects vs. Primitive types
– Example of implementing the Comparable interface