Midterm Review October 23, 2006 ComS 207: Programming I (in Java)

Slides:



Advertisements
Similar presentations
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
Advertisements

5-1 Flow of Control Recitation-01/25/2008  CS 180  Department of Computer Science  Purdue University.
Loops – While, Do, For Repetition Statements Introduction to Arrays
Aalborg Media Lab 23-Jun-15 Software Design Lecture 6 “Conditionals and Loops”
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Logical Operators and Conditional statements
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
CONTROL STATEMENTS Lakhbir Singh(Lect.IT) S.R.S.G.P.C.G. Ludhiana.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Programming in Java (COP 2250) Lecture 11 Chengyong Yang Fall, 2005.
CSCI 1100/1202 January 28, The switch Statement The switch statement provides another means to decide which statement to execute next The switch.
© 2004 Pearson Addison-Wesley. All rights reserved February 17, 2006 The ‘while’ Statement ComS 207: Programming I (in Java) Iowa State University, SPRING.
© 2004 Pearson Addison-Wesley. All rights reserved February 20, 2006 ‘do’ and ‘for’ loops ComS 207: Programming I (in Java) Iowa State University, SPRING.
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
© 2004 Pearson Addison-Wesley. All rights reserved October 19, 2007 Sorting ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
Switch Statements Comparing Exact Values. The Switch Statement: Syntax The switch statement provides another way to decide which statement to execute.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Chapter 6. else-if & switch Copyright © 2012 Pearson Education, Inc.
© 2004 Pearson Addison-Wesley. All rights reserved September 14, 2007 Anatomy of a Method ComS 207: Programming I (in Java) Iowa State University, FALL.
Chapter 5 Conditionals and Loops. © 2004 Pearson Addison-Wesley. All rights reserved5-2 The switch Statement The switch statement provides another way.
Topics Logical Operators (Chapter 5) Comparing Data (Chapter 5) The conditional operator The switch Statement The for loop Nested Loops.
© 2004 Pearson Addison-Wesley. All rights reserved March 10, 2006 Sorting ComS 207: Programming I (in Java) Iowa State University, SPRING 2006 Instructor:
Control statements Mostafa Abdallah
1 b Boolean expressions b truth tables b conditional operator b switch statement b repetition statements: whilewhile do/whiledo/while forfor Lecture 3.
Loops Copyright © 2012 Pearson Education, Inc.. Conditionals and Loops (Chapter 5) So far, we’ve looked at: –making decisions with if –how to compare.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
© 2004 Pearson Addison-Wesley. All rights reserved October 5, 2007 Arrays ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Arrays of Objects October 9, 2006 ComS 207: Programming I (in Java)
CprE 185: Intro to Problem Solving (using C)
Chapter 4 Repetition Statements (loops)
The switch Statement, and Introduction to Looping
Chapter 6 More Conditionals and Loops
Boolean Expressions & the ‘if’ Statement
The switch Statement The switch statement provides another way to decide which statement to execute next The switch statement evaluates an expression,
Chapter 6 More Conditionals and Loops
Debugging October 3, 2007 ComS 207: Programming I (in Java)
Outline Altering flow of control Boolean expressions
Sorting October 20, 2006 ComS 207: Programming I (in Java)
The ‘while’ Statement September 27, 2006
Chapter 3: Program Statements
Logic of an if statement
CprE 185: Intro to Problem Solving (using C)
Debugging October 4, 2006 ComS 207: Programming I (in Java)
Encapsulation September 13, 2006 ComS 207: Programming I (in Java)
Arrays October 6, 2006 ComS 207: Programming I (in Java)
Comparing Data & the ‘switch’ Statement
Comparing Data & the ‘switch’ Statement
CprE 185: Intro to Problem Solving (using C)
Chap 7. Advanced Control Statements in Java
Arrays of Objects October 8, 2007 ComS 207: Programming I (in Java)
Conditionals and Loops
CSCI 1100/1202 February 6, 2002.
‘do’ and ‘for’ loops October 1, 2007 ComS 207: Programming I (in Java)
Controlling Program Flow
Recursion (part 1) October 25, 2006 ComS 207: Programming I (in Java)
CprE 185: Intro to Problem Solving (using C)
Boolean Expressions & the ‘if’ Statement
‘do’ and ‘for’ loops October 2, 2006 ComS 207: Programming I (in Java)
CprE 185: Intro to Problem Solving (using C)
Presentation transcript:

Midterm Review October 23, 2006 ComS 207: Programming I (in Java) Iowa State University, FALL 2006 Instructor: Alexander Stoytchev © 2004 Pearson Addison-Wesley. All rights reserved

Midterm 2 This Tuesday (Oct 24, 2006) Location: Hoover Hall, room 2055 Time: 6:30pm – 7:45pm Try to be there at least 10 minutes early. If you need extra time you can have it but this is **NOT** a 3 hour exam! © 2004 Pearson Addison-Wesley. All rights reserved

Midterm Format Covers Sections 1-5 & 7 Also, Searching and Sorting Format same as Midterm 1 © 2004 Pearson Addison-Wesley. All rights reserved

Midterm Format (last semester) True/False (10 x 1p each = 10p) Short answer ( 5 x 2p each = 10p) Code Snippets ( 5 x 3p each = 15p) Other Stuff ( 3 x 5p each = 15p) Program 1 (15p) Program 2 (15p) Program 3 (15p) Program 4 (20p) TOTAL (130p) © 2004 Pearson Addison-Wesley. All rights reserved

Midterm Format You don’t need to get all 130 points to get an A 100 is a 100 You must get at least 65 points in order to pass this exam © 2004 Pearson Addison-Wesley. All rights reserved

Midterm Format Drop Deadline is next Friday (Oct 27) I cannot guarantee that all exams will be graded by then. If you believe that you did not do well please ask me to grade your exam first at the time when you are submitting it. © 2004 Pearson Addison-Wesley. All rights reserved

Questions © 2004 Pearson Addison-Wesley. All rights reserved

Quick Review of the Material Since Midterm 1 © 2004 Pearson Addison-Wesley. All rights reserved

Encapsulation An encapsulated object can be thought of as a black box -- its inner workings are hidden from the client The client invokes the interface methods of the object, which manages the instance data Methods Data Client © 2004 Pearson Addison-Wesley. All rights reserved

Method Control Flow If the called method is in the same class, only the method name is needed myMethod(); myMethod compute © 2004 Pearson Addison-Wesley. All rights reserved

Method Control Flow The called method is often part of another class or object obj.doIt(); main doIt helpMe helpMe(); © 2004 Pearson Addison-Wesley. All rights reserved

The if Statement The if statement has the following syntax: The condition must be a boolean expression. It must evaluate to either true or false. if is a Java reserved word if ( condition ) statement; If the condition is true, the statement is executed. If it is false, the statement is skipped. © 2004 Pearson Addison-Wesley. All rights reserved

Logic of an if statement condition evaluated false statement true © 2004 Pearson Addison-Wesley. All rights reserved

The if-else Statement An else clause can be added to an if statement to make an if-else statement if ( condition ) statement1; else statement2; If the condition is true, statement1 is executed; if the condition is false, statement2 is executed One or the other will be executed, but not both © 2004 Pearson Addison-Wesley. All rights reserved

Logic of an if-else statement condition evaluated false statement2 statement1 true © 2004 Pearson Addison-Wesley. All rights reserved

Logical Operators A truth table shows all possible true-false combinations of the terms Since && and || each have two operands, there are four possible combinations of conditions a and b a b a && b a || b true false © 2004 Pearson Addison-Wesley. All rights reserved

Boolean Expressions Specific expressions can be evaluated using truth tables total < MAX found !found total < MAX && !found false true © 2004 Pearson Addison-Wesley. All rights reserved

The switch Statement The general syntax of a switch statement is: and case are reserved words switch ( expression ) { case value1 : statement-list1 case value2 : statement-list2 case value3 : statement-list3 case ... } If expression matches value2, control jumps to here © 2004 Pearson Addison-Wesley. All rights reserved

The switch Statement An example of a switch statement: switch (option) { case 'A': aCount++; break; case 'B': bCount++; case 'C': cCount++; } © 2004 Pearson Addison-Wesley. All rights reserved

The do Statement An example of a do loop: int count = 0; do { count++; System.out.println (count); } while (count < 5); The body of a do loop executes at least once See ReverseNumber.java (page 244) © 2004 Pearson Addison-Wesley. All rights reserved

Comparing while and do The while Loop The do Loop statement condition true false condition evaluated The while Loop true condition evaluated statement false The do Loop © 2004 Pearson Addison-Wesley. All rights reserved

The for Statement A for statement has the following syntax: The initialization is executed once before the loop begins The statement is executed until the condition becomes false for ( initialization ; condition ; increment ) statement; The increment portion is executed at the end of each iteration © 2004 Pearson Addison-Wesley. All rights reserved

The for Statement An example of a for loop: for (int count=1; count <= 5; count++) System.out.println (count); The initialization section can be used to declare a variable Like a while loop, the condition of a for loop is tested prior to executing the loop body Therefore, the body of a for loop will execute zero or more times © 2004 Pearson Addison-Wesley. All rights reserved

Logic of a for loop initialization condition evaluated false statement true increment © 2004 Pearson Addison-Wesley. All rights reserved

The for Statement A for loop is functionally equivalent to the following while loop structure: initialization; while ( condition ) { statement; increment; } © 2004 Pearson Addison-Wesley. All rights reserved

Nested Loops How many times will the string "Here" be printed? count1 = 1; while (count1 <= 10) { count2 = 1; while (count2 <= 20) System.out.println ("Here"); count2++; } count1++; 10 * 20 = 200 © 2004 Pearson Addison-Wesley. All rights reserved

Each value has a numeric index Arrays An array is an ordered list of values scores The entire array has a single name Each value has a numeric index 0 1 2 3 4 5 6 7 8 9 79 87 94 82 67 98 87 81 74 91 An array of size N is indexed from zero to N-1 This array holds 10 values that are indexed from 0 to 9 © 2004 Pearson Addison-Wesley. All rights reserved

Arrays Another way to depict the scores array: 79 87 94 82 67 98 81 74 91 © 2004 Pearson Addison-Wesley. All rights reserved

Arrays in Java Java represents 2D arrays as an array of arrays! In other words, a 2D integer array is really a 1D array of references to 1D integer arrays. The concept generalizes to N-dimensions © 2004 Pearson Addison-Wesley. All rights reserved

Anatomy of a 2D Array [http://www.willamette.edu/~gorr/classes/cs231/lectures/chapter9/arrays2d.htm] © 2004 Pearson Addison-Wesley. All rights reserved

Example of a regular 2D array Note: In Java the first index should be 0 not 1! [http://livedocs.macromedia.com/coldfusion/5.0/Developing_ColdFusion_Applications/arrayStruct2.htm] © 2004 Pearson Addison-Wesley. All rights reserved

Example of a Ragged Array Note: In Java the first index should be 0 not 1! [http://livedocs.macromedia.com/coldfusion/5.0/Developing_ColdFusion_Applications/arrayStruct2.htm] © 2004 Pearson Addison-Wesley. All rights reserved

Searching and Sorting Too much stuff to cover again Check the slides and programs on the web page © 2004 Pearson Addison-Wesley. All rights reserved

Animations of Sorting Algoritms http://maven.smith.edu/~thiebaut/java/sort/demo.html http://www.cs.ubc.ca/spider/harrison/Java/sorting-demo.html © 2004 Pearson Addison-Wesley. All rights reserved

Sample Homework Solutions © 2004 Pearson Addison-Wesley. All rights reserved

THE END © 2004 Pearson Addison-Wesley. All rights reserved