1 / 30

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9

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. Review the Class Slides: Key Things to Take Away – Do you understand these the points? Review Slides, especially if some Key Points are unclear

amy-oliver
Download Presentation

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Things to Review • 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

  3. Review the Class Slides • 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

  4. Wk02.1 Slides:Introduction to JavaChapters 1 and 2The Java Language – Section 1.1Data & 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: • 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

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

  7. Key Things to take away: • 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

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

  9. Key Things to take away: • 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

  10. Wk03.1 SlidesConditionals and LoopsChapter 4 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

  11. Key Things to take away: • 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

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

  13. Key Things to take away: • 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

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

  15. Key Things to take away: • 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

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

  17. Question 3 • Work out the logic one step at a time: • True when A is false => !A • Either B or C are true => B || C • AND => both the above must be true • => !A && B || C But remember to check precedence! • => !A && B || C is evaluated as • =>(!A && B)|| C That’s not right! Need to add parenthesis • => !A && (B || C) !A && (B || C) Validate using a Truth Table:

  18. Question 4 • 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! for (int i=1; i <= 9; i += 2) { System.out.println(i); }

  19. Question 5 • Follow the flow of control: • (Sum > MAX) is true since (100 > 10) • So must call Print1, not Print2 • No {} around else, Print3 not part of the if • So Print3 must get printed as well • Print3 is not doing addition, so not 110 • Print3 doing String Concatenation • So will print “100”+”10” => “10010” x x x x √ x

  20. Wk06.3 Slides:Arrays Chapter 7 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

  21. Key Things to take away: • Arrays are an ordered collection on Array Elements • Array Elements may be Primitive Data Types, or Objects • Arrays are objects • Arrays cannot be extended once created • Command Line Parameters are passed as an Array of Strings • Variable Length Parameter lists passed as an Array of Objects • Array Elements may be other Arrays • Arrays may be one, two, or multidimensional

  22. Wk06.5 Slides:Inheritance Chapter 8 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

  23. Key Things to take away: • Inheritance • Inheritance is the process of deriving a new class from an existing class • Inheritance allows software reuse of existing software • Inheritance creates an IS-A relationship between parent and child classes • Protected visibility provides encapsulation and allows inheritance • A parents constructor can and should by invoked by the child via super • A child class can override a parents methods by redefining them • A child of one class can be the parent of another • All Java classes are derived from the Object class • An Abstract class cannot be instantiated, it represents a concept • Abstract classes must be declared in the child before it can be instantiated • Private members of a class and not be seen directly in the child class • The final modifier can be used to restrict inheritance

  24. Wk07.3 Slides:Polymorphism Chapter 9 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

  25. Key Things to take away: • Polymorphism • The term polymorphism literally means “having many forms” • A polymorphic reference is a variable that can refer to different types of objects at different points in time • The method invoked through a polymorphic reference can change from one invocation to the next • It is the type of the object being referenced, not the reference type, that determines which method is invoked • Interfaces allow true encapsulation and hide implementation details • Interfaces are critical for supporting GUIs and other functions cleanly

  26. Review the Quiz Solutions and Assignments • Try to do the Quiz again • It should be now be much easier now. See how long it takes you. • Review the solutions and compare to your answers. • Look at the kind of problems – midterm will be similar • Assignments 2 and 3: • Review the questions – midterm will be similar • There will be programming questions

  27. Review Assignment 2 Solutions • Part A – Written Question Solutions • a2WriteUp • Operator Precedence • Generating Random Numbers • Definite Loops • Indefinite Loops • Part B – Programming Solutions • RandomAvg.java • AvgNums.java • Distance.java • MoneyChanger.java • MoneyCounter.java

  28. Review Assignment 3 Questions • Review the Parts A and B Written Questions • Work on the Written Questions (Part A is due Monday in Lab). • Review Part C Programming Problems • Try to solve questions 1 to 4 before the Midterm Exam if you can

  29. Practice your Programming Skills • Sign up to CodingBat.com and work through the examples. • It will give you immediate feedback and track your progress. • Be sure that you know how to: • write boolean expressions and if-then-else conditions • know how to concatenate, compare, and manipulate Strings • write for, while, and do loops • index into arrays, pass arrays as parameters, 1 and 2 dimensions

  30. Key things you should know for the midterm: • You should be able to: • Understand flow of control and the importance of braces • Describe the various phases of software testing • Write boolean expressions using correct operator precedence • Write programs using if-then-else, for, while, do, switch • know how to concatenate, compare, and manipulate Strings • Understand how Primitive Data and Objects parameters work • Work with Arrays and indexing of Arrays, arrays of objects • Explain elements of good design including coupling and cohesion • Be able to create a data flow diagram based on a problem description • Understand the principles of inheritance and polymorphism • Understand how dynamic-binding of methods enables polymorphism • Describe what an Abstract class is • Describe what an Interface is used for • Understand the function of modifiers public, private, static, and final • Be able to use the super and this keywords within methods

More Related