Midterm Exam 75 points 1 min per point Allocate time proportionate to points Closed book Chapters 1-5 (except char) PDF/PS with index and corrections coming.

Slides:



Advertisements
Similar presentations
© 2007 Lawrenceville Press Slide 1 Assignment Statement An assignment statement gives a value to a variable. Assignment can take several forms: x = 5;
Advertisements

CSCI 160 Midterm Review Rasanjalee DM.
Chapter 7: User-Defined Functions II
Slide 1 Chapter 4 Assignment Statement An assignment statement gives a value to a variable. Assignment can take several forms: x = 5; a literal (5) is.
C OMP 110 S TATE Instructor: Jason Carter. 2 O UTLINE Instance Variables Procedures Properties Print Statements Println vs. Print Overloading.
C OMP 401 C LASS S TATE Instructor: Prasun Dewan.
C OMP 110 S TYLE Instructor: Jason Carter. 2 I NTERFACES AND M ORE S TYLE Define contracts between our users and implementers Optional – they may not.
C OMP 110 L OAN C ASE S TUDY Instructor: Jason Carter.
C OMP 110 O BJECTS Instructor: Jason Carter. 2 C OMPUTER VS. P ROGRAM M ODEL Processor Compiler Program (source code)
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
Road Map Introduction to object oriented programming. Classes
By - Qiong Han. DON’T FALL BEHIND IN READING Submission Instruction Everyone needs to submit the printed HARD- COPY of the codes and the grading sheets.
Object-based Programming Intuitive explanation Using objects to read input Creating objects Style rules.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Program Style Identifier Names Comments Named Constants Avoiding Code Repetition Giving Least Privilege Efficiency Interfaces.
Comp 14 (3) By Stephan Sherman Office hours, W, 3:00-3:50pm.
Object-based Programming Intuitive explanation Using objects to read input Creating objects Style rules.
Wednesday, 12/11/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Wednesday, 12/11/02  QUESTIONS??  Today: CLOSING CEREMONIES!  HW #5 – Back Monday (12/16)
Chapter 3 Classes and Methods. 2 Knowledge Goals Appreciate the difference between a class in the abstract sense and a class as a Java construct Know.
Wednesday, 10/9/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 10/9/02  QUESTIONS ??  Today:  Discuss HW #02  Discuss test question types  Review 
Programmer-Defined Types Object Types as Programmer-defined Types Two-way Dependencies Representation Errors Primitive Vs Object Properties Constructors.
More on Conditionals Miscellaneous (Side effects) Style issues Early returns.
Object Types Primitive types Primitive Vs Object Types Types Classes ABMISpreadsheet AnotherBMISpreadsheet Interfaces BMISpreadsheet Loan Stringdoubleint.
Object-based Programming Intuitive explanation Two concrete examples Calculators addition BMI Programming Environment.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
ObjectEditor Prasun Dewan Comp 114. ObjectEditor Automatic user-interface generation. You only write computation code Separate object to do I/O Main just.
Midterm Exam 2 75 points 1 min per point Allocate time proportionate to points Closed book Chapters 6-9 Look at exercises.
State Instance Variables Procedures Properties Print Statements Println Vs Print Overloading J++
Bicycle Car Types pedal() pushAccelerator(). Stringdoubleint Programming Language Types “three”“four” = 7 = “threefour” + + / = 0 / = 0.75.
Introduction to Information and Computer Science Computer Programming Lecture c This material (Comp4_Unit5c), was developed by Oregon Health and Science.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Chapter 06 (Part I) Functions and an Introduction to Recursion.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
C OMP 401: C ONSTRUCTORS AND P OINTERS Instructor: Prasun Dewan (FB 150,
CSE1222: Lecture 3The Ohio State University1. Assignment Operations  The C++ assignment operator is: =  Examples: x = 3 * 5; y = x – 7; y = y + 4; Do.
C OMP 110 T YPES Instructor: Prasun Dewan 2 P REREQUISITES Interfaces.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
C OMP 110/401 D OCUMENTATION : C OMMENTS Instructor: Prasun Dewan.
Programming Process Programming in Java is an exercise in using pre-defined classes and writing new classes to fill in the gaps A procedure for determining.
C OMP 110/401 E NCAPSULATION AND L EAST P RIVILEGE Instructor: Prasun Dewan.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
CSCI 1226 FALL 2015 MIDTERM #1 REVIEWS.  Types of computers:  Personal computers  Embedded systems  Servers  Hardware:  I/O devices: mice, keyboards,
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
C OMP 110/401 D OCUMENTATION : A NNOTATIONS Instructor: Prasun Dewan.
Inside Class Methods Chapter 4. 4 What are variables? Variables store values within methods and may change value as the method processes data.
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Chapter 4 Assignment Statement
Chapter 7: User-Defined Functions II
Chapter 3 Assignment Statement
Java Programming: From Problem Analysis to Program Design, 4e
Instructor: Prasun Dewan
Chapter 2: Basic Elements of Java
Review for Final Exam.
Comp 110/401 Documentation: Comments
Recitation 4 September 16, 2011.
Unit 3 Test: Friday.
Review for Final Exam.
Recitation 3 September 9, 2011 Wade Gobel.
Chapter 2 Programming Basics.
Relational Operators.
Corresponds with Chapter 5
Presentation transcript:

Midterm Exam 75 points 1 min per point Allocate time proportionate to points Closed book Chapters 1-5 (except char) PDF/PS with index and corrections coming Look at exercises

Exam Question Difficulty Obvious questions Questions requiring studying Challenging questions

Question Nature Essay Questions Understanding Code Writing/Modifying Code Example syntax

Essay Questions Definitions –Define class. Distinction –Distinguish Expression from Statement. Rationale –Why style principles? Comparison –Pros and Cons of using Named Constants & Literals.

Understanding Code Identify Errors and Style Principle Violations class aMoneyconverter { int Cents (dollars) { return dollars*100; } }

Understanding Code Classify Components –properties, variables, signatures …. public class C () { public int m = 100; public int getD() { return m; } public void setD(int i) { m = i; } public int getC() { return m*100; } public int convert (int i) { return i*100; } `}`}

Understanding Code Evaluate Method Calls public class C () { public int m = 100; public int getD() { return m; } public void setD(int i) { m = i; } public int getC() { return m*100; } public int convert (int i) { return i*100; } `}

Understanding Code Evaluate, Parenthesize, and Type Expressions ExpressionTypeValue int8

Understanding Code Parenthesize Expressions ExpressionParenthesized (5-3) - 3

Writing Code Improve Code public class C () { public int m = 100; public int getD() { return m; } public void setD(int i) { m = i; } public int getC() { return m*100; } public int convert (int i) { return i*100; } `}

Writing Code Write Expressions –i is 2 –Answer: i == 2 Method –cube(x) Class, Interface –Like assignments

Declarations Vs Statement Order Order of variable and method declarations in a class does not matter in Java. Order of statements in a method body matters. –Statements executed sequentially.

Expressions Vs Statements Expression: Piece of code yielding value 5 “setWeight called” newHeight x*x weight/(height*height) Statement: computer instruction executed autonomously System.out.println(“seW eight called”); return x*x bmi = weight/(height*height); Expression always evaluated as part of some statement.

Pure Vs Impure Functions ABMISpreadsheet Instance getWeight weight Body accesses calculateBMI(77,1.77) getWeight() setWeight(77) setWeight(71) ABMICalculator Instance calculateBMI weight Body accesses height

public class AnotherBMISpreadsheet implements BMISpreadsheet{ double height, weight, bmi; public double getHeight() { return height; } public void setHeight(double newHeight) { height = newHeight; bmi = calculateBMI(); } public double getWeight() { return weight; } public void setWeight(double newWeight) { weight = newWeight; bmi = calculateBMI(); } public double getBMI() { return bmi; } double calculateBMI() { double heightInMetres = height*CMS_IN_INCH/100; return (weight/LBS_IN_KG) / (heightInMetres*heightInMetres); } Scope heightInMetres Scope height Scope illegal Scope

public class AnotherBMISpreadsheet implements BMISpreadsheet{ double height, weight, bmi; public double getHeight() { return height; }... } Scope getHeight() Scope ObjectEditor ABMISpreadsheet

Identifier Scope Region of code where the identifier is visible. Arbitrary scopes not possible Least Privilege => Make scope as small as possible

public class AnotherBMISpreadsheet implements BMISpreadsheet{ double height, weight, bmi; public void setHeight(double newHeight) { double height = heightInMetres; bmi = calculateBMI(); }... final double LBS_IN_KG = 2.2; final double CMS_IN_INCH = 2.54; double calculateBMI() { double heightInMetres = height*CMS_IN_INCH/100; return (weight/LBS_IN_KG) / (heightInMetres*heightInMetres); } Scope heightInMetres Scope