reviewing for the midterm
play

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9 - PowerPoint PPT Presentation

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Things to Review 2 Review the Class Slides: Key Things to Take Away Do you understand these the points?


  1. Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

  2. Things to Review 2 Review the Class Slides: • Key Things to Take Away – Do you understand these the points? • Review Slides, especially if some Key Points are unclear Make use of the Textbook • Answer Self-Review Questions at back of each chapter • Select Exercises and Programming Projects to practice Review Quiz and Assignments • Do you understand how to answer Assignment 3 Written Questions? • Review Quiz #1 and Assignment #2 questions, then see the solutions Get some Coding Practice! • Sign up on CodingBat.com and work through the problems there Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 2 Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase

  3. Review the Class Slides 3 Week 01 • wk01.3 – Background Info, Introduction Week 02 • wk02.1 – Introduction to Java • wk02.3 – Intro to Objects and String and Scanner Objects • wk02.5 – Packages Enums and Wrappers Week 03 • wk03.1 – Boolean Expressions, Conditionals, Definite Loops Week 04 • wk04.1 – Structured Analysis and Data Flow Diagrams • wk04.3 – Review Week 05 • wk05.1 – Writing Classes • wk05.5 – Quiz 1 Solutions Week 06 • wk06.1 – Testing • wk06.3 – Arrays • wk06.5 – Inheritance Week 07 • wk07.3 – Polymorphism Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 3 Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase

  4. Wk02.1 Slides: Introduction to Java Chapters 1 and 2 The Java Language – Section 1.1 Data & Expressions – Sections 2.1 – 2.5 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

  5. Ch 1&2 - Key Things to take away: 5 • The print and println methods are two services provided by the System.out object • In Java, the + operator is used both for addition and for string concatenation • An escape character can be used to represent a character that would otherwise cause a compile error • A variable is a name for a memory location used to hold a value of a particular data type • Accessing data leaves them intact in memory, but an assignment statement overwrites old data • One cannot assign a value of one type to a variable of an incompatible type • Constants hold a particular value for the duration of their existence • Java has two types of numeric values: integer and floating point. There are four integer data types and two floating point data types • Java using 16-bit Unicode character set to represent character data • Expressions are combinations of operators and operands used to perform a calculation • The type of result produced by arithmetic division depends on the types of the operands • Java follows a well-defined set of precedence rules that governs the order in which operators will be evaluated in an expression • Narrowing conversions should be avoided because they can lose information Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 5 Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase

  6. Wk02.3 Slides: Using Classes and Objects Chapters 3 Creating Objects – Section 3.1 The String Class – Section 3.2 The Scanner Class – Section 2.6 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

  7. Key Things to take away: 7 • Object declarations create place holders which point to an object in memory • The new operator instantiates a new instance of the class • Strings are immutable – changing a string creates a new instance • A variable holds either a primitive type or a reference to an object • Assigning variables of primitive types copies the value • Assigning variables of class types copies a reference to the object • The String class provides useful methods for working with strings length • concat • substring • toUpperCase • • Etc • The System.in object represents the standard input stream • The Scanner Class provides methods for reading input values Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 7 Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase

  8. Wk02.5 Slides: Using Classes and Objects Chapters 3 Section 3.3 Packages Section 3.4 Random Class Section 3.5 Math Class Section 3.7 Enumerated Types Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

  9. Key Things to take away: 9 • The Java API contains standard set of class definitions • Class definitions can be reused by importing packages • Packages exist for creating random numbers, math, and formatting • You can create your own set of libraries as a package • Java provides wrapper classes for primitive data types so they can be used just like any other object Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 9 Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase

  10. Wk03.1 Slides Conditionals and Loops Chapter 4 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

  11. Key Things to take away: 11 • Flow of Control determines which statements get executed • Expressions can form complex conditions using logical operators • AND and OR evaluation are short-circuited in Java • Selection statements chose different execution paths based on conditions • If <condition> then <statement>; • If <condition> then <statement1> else <statement2>; • Switch <integer value> {Case 1, Case 2, … Case N} • Java supports two styles of Indefinite Loops: • While <condition> <statement>; • Do <statement> while <condition>; • Java suports two styles of definite Loops: • for ( initialization ; condition ; increment ) <statement>; • For-each using Iterators Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 11 Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase

  12. Wk04.1 - Wk05.5 Slides: Writing Classes Chapter 5 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

  13. Key Things to take away: 13 Class and Method Design • Data Flow Diagrams help get a design started • Problem Specification: Nouns become Classes, Verbs become Methods • Decompose methods that get too complex Class and Method Coding • Methods and Variables have Scope – where they can be seen • Public Scope allows access by users of the Class • Private Scope used to encapsulate data and internal helper methods • Invoking a method copies the actual parameters into the formal parameters • Object Parameters contain references to the actual object and can be modified Testing • Methodical Testing is important step, every program has bugs • Testing can be black box (functional) or white box (implementation) • Four types of tests: Unit, Integration, System, Regression • Println’s and the Eclipse Debugger are essential tools for debugging Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 13 Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase

  14. Wk04.3 Slides: Review Chapters 1 to 4 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

  15. Key Things to take away: 15 • Flow of Control determines which statements get executed • Expressions can form complex conditions using logical operators • AND and OR evaluation are short-circuited in Java • Selection statements chose different execution paths based on conditions • If <condition> then <statement>; • If <condition> then <statement1> else <statement2>; • Switch <integer value> {Case 1, Case 2, … Case N} • Java supports two styles of Indefinite Loops: • While <condition> <statement>; • Do <statement> while <condition>; • Java suports two styles of definite Loops: • for ( initialization ; condition ; increment ) <statement>; • For-each using Iterators Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 15 Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase

  16. Wk05.5 Slides: Quiz #1 Solutions Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

  17. Question 3 17 !A && (B || C) Work out the logic one step at a time: Validate using a Truth Table: • True when A is false => !A A B C !A B||C !A && (B || C) • Either B or C are true => B || C F F F T F F • AND => both the above must be true => !A && B || C • F F T T T T But remember to check precedence! F T F T T T => !A && B || C is evaluated as • =>( !A && B)|| C • F T T T T T That’s not right! T F F F F F Need to add parenthesis => !A && (B || C) T F T F T F • T T F F T F T T T F T F Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 17 Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase

  18. Question 4 18 for (int i=1; i <= 9; i += 2) { System.out.println(i); } For full marks, • Do not go through the loop 9 times, execute the loop 5 times • Realize that you can increment counter by 2 within the loop, not by 1 twice • Declare the loop variable within the for loop If you do not remember HOW to write a Java for loop… • Use Appendix J – it was attached at the back! Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 18 Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend