ap computer science a jacobson week 1 second semester

48
AP Computer Science A Jacobson Week 1 Second Semester

Upload: augustine-hawkins

Post on 28-Dec-2015

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: AP Computer Science A Jacobson Week 1 Second Semester

AP Computer Science A

Jacobson

Week 1

Second Semester

Page 2: 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

Page 3: AP Computer Science A Jacobson Week 1 Second Semester

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.

Page 4: AP Computer Science A Jacobson Week 1 Second Semester

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.

Page 5: AP Computer Science A Jacobson Week 1 Second Semester

Share with Class

Page 6: AP Computer Science A Jacobson Week 1 Second Semester

Mr. Jacobson’s Reflections

Positives

Hard work- Diligence

Problem solving skills are starting to show

Semester Project

Page 7: AP Computer Science A Jacobson Week 1 Second Semester

Mr. Jacobson’s Reflections

Negatives

Page 8: AP Computer Science A Jacobson Week 1 Second Semester

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

Page 9: AP Computer Science A Jacobson Week 1 Second Semester

Mr. Jacobson’s Reflections

Places for Change

More responsive assessments

More student participation

Less “distractions”

Page 10: AP Computer Science A Jacobson Week 1 Second Semester

Book Check

• Collect all Simply Java

• Check the number of the other textbook

Page 11: AP Computer Science A Jacobson Week 1 Second Semester

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

Page 12: AP Computer Science A Jacobson Week 1 Second Semester

Marine Biology Case Study

• Getting it running

Page 13: AP Computer Science A Jacobson Week 1 Second Semester

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;

Page 14: AP Computer Science A Jacobson Week 1 Second Semester

Agenda

• Finish Chapter 1 Case Study– Work together– Class discussion

• Truth Tables

Page 15: AP Computer Science A Jacobson Week 1 Second Semester

Case Study

Page 16: AP Computer Science A Jacobson Week 1 Second Semester
Page 17: AP Computer Science A Jacobson Week 1 Second Semester

Objective-Truth tables

Today you will make a truth table for a complex logical expression and apply that to java programming.

Page 18: AP Computer Science A Jacobson Week 1 Second Semester

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

Page 19: AP Computer Science A Jacobson Week 1 Second Semester

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

Page 20: AP Computer Science A Jacobson Week 1 Second Semester

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

Page 21: AP Computer Science A Jacobson Week 1 Second Semester

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

Page 22: AP Computer Science A Jacobson Week 1 Second Semester

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

Page 23: AP Computer Science A Jacobson Week 1 Second Semester

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

Page 24: AP Computer Science A Jacobson Week 1 Second Semester

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

Page 25: AP Computer Science A Jacobson Week 1 Second Semester

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

Page 26: AP Computer Science A Jacobson Week 1 Second Semester

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

Page 27: AP Computer Science A Jacobson Week 1 Second Semester

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

Page 28: AP Computer Science A Jacobson Week 1 Second Semester

Warm up picture

Mystery

x

printStuff (int x)

x

y

OUTPUT

Page 29: AP Computer Science A Jacobson Week 1 Second Semester

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

Page 30: AP Computer Science A Jacobson Week 1 Second Semester

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)

Page 31: AP Computer Science A Jacobson Week 1 Second Semester

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

Page 32: AP Computer Science A Jacobson Week 1 Second Semester

Study Sessions

Page 33: AP Computer Science A Jacobson Week 1 Second Semester

Tracing the Code

• Where were we last time?

• Parameter Passing Example– Pages 253-255

Page 34: AP Computer Science A Jacobson Week 1 Second Semester

Agenda 2-17-06

• Collect HW

• Programming Projects p.294 5.1

• Finish the Chapter– interface

• Making one

• Using one

Page 35: AP Computer Science A Jacobson Week 1 Second Semester

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

Page 36: AP Computer Science A Jacobson Week 1 Second Semester

Time to Imagine…

Imagine a bunch of 4 year olds in the middle of a basketball court

Page 37: AP Computer Science A Jacobson Week 1 Second Semester

Time to Imagine…

And the adult in charge says “ OK, RUN!!!”What will happen?

Page 38: AP Computer Science A Jacobson Week 1 Second Semester

Time to Imagine…

Now imagine the same set up with the following exception:

Page 39: AP Computer Science A Jacobson Week 1 Second Semester

Time to Imagine…

A series of walls are put up. What will the kids do in this case?

Page 40: AP Computer Science A Jacobson Week 1 Second Semester

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.

Page 41: AP Computer Science A Jacobson Week 1 Second Semester

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

Page 42: AP Computer Science A Jacobson Week 1 Second Semester

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.

Page 43: AP Computer Science A Jacobson Week 1 Second Semester

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?

Page 44: AP Computer Science A Jacobson Week 1 Second Semester

“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();}

Page 45: AP Computer Science A Jacobson Week 1 Second Semester

“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

Page 46: AP Computer Science A Jacobson Week 1 Second Semester

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)

Page 47: AP Computer Science A Jacobson Week 1 Second Semester

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

Page 48: AP Computer Science A Jacobson Week 1 Second Semester

Test Topics

• Chapter 4

• Chapter 5 up to 5.4– Example of Parameter Passing

• Objects vs. Primitive types

– Example of implementing the Comparable interface