CSE 8A Lecture 12. Reading for next class: : Sounds! Today s topics: Logical Operators:! && Start PSA 6: Chromakey!

Similar documents
CS111: PROGRAMMING LANGUAGE II

CSE 8A Lecture 13. Reading for next class: Today s topics: Finish PSA 6: Chromakey! DUE TUESDAY Interm exam 3 next Friday. Sounds!

CSE 8A Lecture 20. LAST WEEK! You made it! (Almost ) PSA 9 due tonight (yayy!! Last one) Bring graded Exam #4 to Wed 3/13/13 lecture for review

CSC 1051 Algorithms and Data Structures I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CSC 1051 Algorithms and Data Structures I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CSC 1051 Data Structures and Algorithms I

Introduction to Computer Science Unit 2. Exercises

CSE 8A Lecture 8. Reading for next class: 6.1 PSA4: DUE 11:59pm tonight (Collage and Picture Flip) PSA3 Interview, deadline Thursday 2/7 noon!

1 Short Answer (10 Points Each)

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1

Algorithms and Conditionals

CSE 8A Lecture 10. Reading for next class: 6.3 PSA4 Interview: due tomorrow, don t forget PSA5: Posted (get started) Today (random useful stuff):

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

CSE 8A Lecture 21. SMarx extra final exam office hours Fri 3/15 11:15am-1pm EBU-3B #2206

CSC 1051 Data Structures and Algorithms I

Menu Driven Systems. While loops, menus and the switch statement. Mairead Meagher Dr. Siobhán Drohan. Produced by:

Programming with Java

AYBUKE BUYUKCAYLI KORAY OZUYAR MUSTAFA SOYLU. Week 21/02/ /02/2007 Lecture Notes: ASCII

Practice Midterm 1 Answer Key

Nested Loops ***** ***** ***** ***** ***** We know we can print out one line of this square as follows: System.out.

First Java Program - Output to the Screen

CSE 1223: Introduction to Computer Programming in Java Chapter 3 Branching

AP COMPUTER SCIENCE A

Selection Statements and operators

if Statement Numeric Rela5onal Operators The if Statement Flow of Control: Branching (Savitch, Chapter 3)

CS111: PROGRAMMING LANGUAGE II

if Statement Numeric Rela7onal Operators The if Statement Flow of Control: Branching (Savitch, Chapter 3)

Fundamentals of Programming Data Types & Methods

CS110 Programming Language I. Lab 6: Multiple branching Mechanisms

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15

CSC 1051 Data Structures and Algorithms I

CSC 1051 Villanova University. CSC 1051 Data Structures and Algorithms I. Course website:

Claremont McKenna College Computer Science

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Ch. 6. User-Defined Methods

CSE8A Lecture 4 IN TERM EXAM 1 THIS FRIDAY. PSA2 published soon watch weebly web page; due next Monday

CompSci 125 Lecture 11

TOPIC 10 THE IF STATEMENT. Making Decisions. Making Decisions. If Statement Syntax. If Statement

5) (4 points) What is the value of the boolean variable equals after the following statement?

TOPIC 10 THE IF STATEMENT

Midterm Review Session

Selection and Repetition Revisited

CSC1590 Java Assignment 2-0. User Defined Classes

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

Algorithms and Java basics: pseudocode, variables, assignment, and interactive programs

CS 106 Introduction to Computer Science I

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18

Constants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous

COMP 202. Programming With Iterations. CONTENT: The WHILE, DO and FOR Statements. COMP Loops 1

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

1 Short Answer (15 Points Each)

CSE 1223: Exam II Autumn 2016

Algorithms and Java basics: pseudocode, variables, assignment, and interactive programs

Oct Decision Structures cont d

Practice Midterm 1. Problem Points Score TOTAL 50

AP CS Unit 3: Control Structures Notes

Selection Statements and operators

CS 106 Introduction to Computer Science I

FOR INTERNAL SCRUTINY (date of this version: 17/2/2016) UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS

Module 3 SELECTION STRUCTURES 2/15/19 CSE 1321 MODULE 3 1

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

CSE 142 Sample Midterm Exam #3

Conditional Programming

Important Java terminology

Unit 4: Classes and Objects Exercises

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

Introduction to Java (All the Basic Stuff)

H212 Introduction to Software Systems Honors

Faculty of Science Midterm. COMP-202B - Introduction to Computing I (Winter 2008)

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Lecture Set 2: Starting Java

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 9, Name: KEY

int x = 42, y = 33; //1 int z = x + y; //2 System.out.println(x + "+" + y + "=" + z); //3

CMPT 125: Lecture 4 Conditionals and Loops

Lec 7. for loops and methods

Loops. CSE 114, Computer Science 1 Stony Brook University

STUDENT LESSON A12 Iterations

Lecture Set 2: Starting Java

CONTENTS: While loops Class (static) variables and constants Top Down Programming For loops Nested Loops

CSE 11 Midterm Fall 2008

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Administration. Conditional Statements. Agenda. Syntax. Flow of control. Lab 2 due now on floppy Lab 3 due tomorrow via FTP

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

Java Coding 3. Over & over again!

SECONDARY SCHOOL, L-IMRIEĦEL HALF YEARLY EXAMINATIONS 2016/2017

Session 14 March 31, 2018

CSE 114 Computer Science I

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

Chapter 9 Lab Text Processing and Wrapper Classes

Handout 4 Conditionals. Boolean Expressions.

TUGCE KEMEROZ - ASLI OZKAN - AYSE TARTAN. Week 12/02/ /02/2007 Lecture Notes:

CS 101 Fall 2006 Midterm 1 Name: ID:

CS61B Lecture #2. Public Service Announcements:

Lec 3. Compilers, Debugging, Hello World, and Variables

Repetition CSC 121 Fall 2014 Howard Rosenthal

Loop - 3 & Class. Cheng, Wei COMP May 22, Title

Warm up Exercise. What are the types and values of the following expressions: * (3 + 1) 3 / / 2.0 (int)1.0 / 2

Transcription:

CSE 8A Lecture 12 Reading for next class: 8.1-8.3: Sounds! Today s topics: Logical Operators:! && Start PSA 6: Chromakey! A vote for CSE 8A Yen Chuan (Allen) Liu and Pin (Arthur) Chu

1) Solo: (30 sec) 2) Discuss/Group: (1 min) Review: If-statements Which statement is most true about ONE execution of this code? if (Math.abs(topAv botav) < 10) topp.setcolor(color.white); else topp.setcolor(color.black); A. It is possible BOTH Section A AND Section B will be executed B. Either Section A will be executed, OR Section B will be executed, but NOT BOTH C. It is possible neither Section A nor Section B will be executed.

Confused? See page 187 for execution flow diagram 1) Solo: (30 sec) 2) Discuss/Group: (1 min) Review: If-statements Which statement is most true about ONE execution of this code? if (Math.abs(topAv botav) < 10) topp.setcolor(color.white); else if (Math.abs(topAv botav < 50) topp.setcolor(color.grey); else topp.setcolor(color.black); A. Exactly one of Section A, Section B, or Section C will be executed B. It is possible that both Section B and Section C will be executed C. It is possible that both Section A and Section C will be executed D. It s possible Sections A, B, and C will be executed

If-statements and pretty pictures

Image courtesy of Aaron Gable, CS 5 Black

Image courtesy of Aaron Gable, CS 5 Black

1) Solo: (30 sec) 2) Discuss/Group: (2 min) Chromakey: Visit strange new places 1 2 background person (before) person (after) In order to create/modify the person picture so that it looks like the after Picture, from which pictures do you take the pixels in the boxes? A. Box 1 (yellow) from background, box 2 (green) from person B. Box 1 from background, box 2 from background C. Box 1 from person, box 2 from person D. Box 1 from person, box 2 from background E. None of the above

1) Solo: (30 sec) 2) Discuss/Group: (30 sec) How will you know which part (yellow box or green) you are in? A. Condition on the Pixel coordinates (not the color) B. Condition on the Pixel colors in background C. Depends on the Pixel colors in person D. Depends on the Pixel colors in background, compared to those at the same coordinates in person background person (before) 1 2

Your chromakey Call two chromakey methods: One to replace background One to replace t-shirt If there are 2 or more people in the picture, you can call more methods one to replace each t-shirt with a different background if you like public void chromakeyblue( Picture newpictoreplaceblue, int bluethreshold ) for( int x = 0; x < this.getwidth(); x++ ) for( int y = 0; y < this.getheight(); y++ ) { //Do some stuff } OK to edit pictures before the code runs

1) Solo: (30 sec) 2) Discuss/Group: (1 min) Review: If-statements int x = 4; if( --x < 4 ) if ( x++ > 2 ) System.out.println( x + 3 ); if( x > 0 && x < 10 ) System.out.println( x += 3 ); 2. What does the code above print? A. 7 B. 6 C. 7 D. other 7 7 10

1) Solo: (30 sec) 2) Discuss/Group: (1 min) Review: If-statements int x = 4; if( --x < 4 ) if ( x++ > 3 ) { x += 3; System.out.println( x ); { else System.out.println( x ); 2. What does the code above print? A. 3 B. 6 C. 7 D. other

1) Solo: (30 sec) 2) Discuss/Group: (1 min) Review: If-statements int x = 4; if( x-- < 5 ) if( x++ > 4 ) System.out.println( x += 3 ); else if( 2 < x x < 5 ) x += 2; System.out.println( x ); 2. What does the code above print? A. 8 B. 6 C. 7 D. other 8 9

! && LOGICAL OPERATORS boolean data type has values: true or false! NOT OPERATOR!false ---> true!true ---> false OR OPERATOR && AND OPERATOR true true ---> true true && true ---> true true false ---> true true && false ---> false false true ---> true false && true ---> false false false ---> false false && false ---> false

What line of code goes in the blank? public static boolean isvalid( int n, int min, int max ) { if( (min < n)??? (n < max) ) return true; else // Necessary? return false; } A. B. && C. other

CS Concept: Booleans are values if ( absvalz < 2.0 ) return true; else return false; Which of the following is equivalent to the above code? A. return absvalz; B. return absvalz < 2.0; C. return absvalz >= 2.0; D. None of these

What line of code goes in the blank? public static boolean isalpha( char ch ) { if( ( A < ch (1) ch < Z ) (2) ( a < ch (3) ch < z ) ) return true; else // Necessary? return false; } A. && && && B. && && C. && D. other

1) Solo: (30 sec) 2) Discuss/Group: (1 min) Review: loops int x = 6; while( --x > 2 ) System.out.println( x - 2 ); System.out.println( x ); 2. What does the code above print? A. 4 B. 3 C. 3 D. other 3 2 2 2 1 2

1) Solo: (30 sec) 2) Discuss/Group: (1 min) Review: loops boolean b = false ; while( b == true ) System.out.println( hi ); System.out.println( bye ); 2. What does the code above print? A. hi B. bye C. hi D. other bye hi

1) Solo: (30 sec) 2) Discuss/Group: (1 min) Review: loops boolean b = false ; while( b = true ) // careful System.out.println( hi ); System.out.println( bye ); 2. What does the code above print? A. hi B. bye C. hi D. other bye hi

What line of code goes in the blank? public static void readvalidage( ) { int age; Scanner scan = new Scanner(System.in); // Keyboard input } do { System.out.print( Enter your age: ); age = scan.nextint(); } while( (1) ); A. (age > 0) (123 > age) B. (age < 0) (123 < age) C. (age < 0) && (123 < age) D. other

What line of code goes in the blank? public static void main( String [] args ) { int answer; Scanner scan = new Scanner(System.in); // Keyboard input do { /* Some code here */ System.out.print( Want to repeat program (1:yes 2:no 3:NO)? ); answer = scan.nextint(); } while( (1) ); } A. (answer!= 2) (answer!= 3) B. answer!= 1 C. (answer!= 2) && (answer!= 3) D. other

if-statements Logical Operators Loops Review Summary of Concepts

TODO Reading for next class: 8.1-8.3 (Sounds) Start PSA6