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

Similar documents
Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Introduction to Programming Using Java (98-388)

Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Using Classes and Objects Chapters 3 Creating Objects Section 3.1 The String Class Section 3.2 The Scanner Class Section 2.6

Review for Midterm. Instructor: Scott Kristjanson CMPT 135 SFU Surrey, Spring 2016


Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

EECS168 Exam 3 Review

WA1278 Introduction to Java Using Eclipse

Chapter 2: Data and Expressions

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

CS111: PROGRAMMING LANGUAGE II

Full file at

A variable is a name for a location in memory A variable must be declared

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Contents Chapter 1 Introduction to Programming and the Java Language

5/23/2015. Core Java Syllabus. VikRam ShaRma

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

Curriculum Map Grade(s): Subject: AP Computer Science

102. Introduction to Java Programming

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

Java Primer 1: Types, Classes and Operators

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

COMP 202 Java in one week

Computer Science II (20073) Week 1: Review and Inheritance

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:

COP 3330 Final Exam Review

Full file at


Chapter 2: Data and Expressions

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

CS 251 Intermediate Programming Methods and Classes

B. Subject-specific skills B1. Problem solving skills: Supply the student with the ability to solve different problems related to the topics

Glossary. For Introduction to Programming Using Python By Y. Daniel Liang

Index COPYRIGHTED MATERIAL

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.

CO Java SE 8: Fundamentals

Java for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points.

I. Variables and Data Type week 3

Language Features. 1. The primitive types int, double, and boolean are part of the AP

CSC Java Programming, Fall Java Data Types and Control Constructs

CMPT 125: Lecture 3 Data and Expressions

CHAPTER 7 OBJECTS AND CLASSES

Inheritance and Polymorphism

Recursion Chapter 17. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

WEEK 4 OPERATORS, EXPRESSIONS AND STATEMENTS

CS 251 Intermediate Programming Methods and More

CS313D: ADVANCED PROGRAMMING LANGUAGE

Data Conversion & Scanner Class

Absolute C++ Walter Savitch

Chapter 2: Data and Expressions

Robots. Byron Weber Becker. chapter 6

College Board. AP CS A Labs Magpie, Elevens, and Picture Lab. New York: College Entrance Examination Board, 2013.

Program Elements -- Introduction

F1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept

CS1004: Intro to CS in Java, Spring 2005

1 Shyam sir JAVA Notes

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

KOMAR UNIVERSITY OF SCIENCE AND TECHNOLOGY (KUST)

Collections Chapter 12. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

CS171:Introduction to Computer Science II

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Java Fall 2018 Margaret Reid-Miller

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

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

Computer Science II (20082) Week 1: Review and Inheritance

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers)

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content

CS11 Java. Fall Lecture 1

Java for Non Majors Spring 2018

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

CS260 Intro to Java & Android 03.Java Language Basics

Chapter 6 Introduction to Defining Classes

Mathematics/Science Department Kirkwood Community College. Course Syllabus. Computer Science CSC142 1/10

JAVA REVIEW cs2420 Introduction to Algorithms and Data Structures Spring 2015

Chapter 4: Writing Classes

KLiC C++ Programming. (KLiC Certificate in C++ Programming)

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

Computational Expression

CSC207H: Software Design. Java + OOP. CSC207 Winter 2018

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)

CS 231 Data Structures and Algorithms, Fall 2016

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

CHAPTER 7 OBJECTS AND CLASSES

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo

COE318 Lecture Notes Week 4 (Sept 26, 2011)

Building Java Programs

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

13 th Windsor Regional Secondary School Computer Programming Competition

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

This course supports the assessment for Scripting and Programming Applications. The course covers 4 competencies and represents 4 competency units.

Chief Reader Report on Student Responses:

Lecture 5: Methods CS2301

ECE 122 Engineering Problem Solving with Java

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Transcription:

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 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 Wk07.5 Slide 2

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 Wk07.5 Slide 3

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: 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 Wk07.5 Slide 5

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

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 Wk07.5 Slide 7

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

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 Wk07.5 Slide 9

Wk03.1 Slides Conditionals and Loops Chapter 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 Wk07.5 Slide 11

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: 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 Wk07.5 Slide 13

Wk04.3 Slides: Review Chapters 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 Wk07.5 Slide 15

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

Question 3 17!A && (B C) 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) Validate using a Truth Table: A B C!A B C!A && (B C) F F F T F F F F T T T T F T F T T T F T T T T T T F F F F F T F T F T F T T F F T F T T T F T F Wk07.5 Slide 17

18 Question 4 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! Wk07.5 Slide 18

19 Question 5 x x x x 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 Wk07.5 Slide 19

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 Wk07.5 Slide 21

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 Wk07.5 Slide 23

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 Wk07.5 Slide 25

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 Wk07.5 Slide 26

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 Wk07.5 Slide 27

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 Wk07.5 Slide 28

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 Wk07.5 Slide 29

Key things you should know for the midterm: 30 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 Wk07.5 Slide 30