DOC PREVIEW
UNC-Chapel Hill COMP 14 - COMP 14 Midterm Ecam

This preview shows page 1-2-3-4-5-6 out of 18 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

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 Expression Type Value 5 3 4 int 8 Understanding Code Parenthesize Expressions Expression Parenthesized 5 3 3 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 ABMICalculator Instance ABMISpreadsheet Instance calculateBMI getWeight Body accesses Body accesses weight weight height setWeight 77 calculateBMI 77 1 77 24 57 77 setWeight 71 calculateBMI 77 1 77 getWeight 24 57 getWeight 71 Scope public class AnotherBMISpreadsheet implements BMISpreadsheet height Scope double height weight bmi public double getHeight illegal Scope 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 heightInMetres public double getBMI Scope return bmi double calculateBMI double heightInMetres height CMS IN INCH 100 return weight LBS IN KG heightInMetres heightInMetres Scope getHeight Scope public class AnotherBMISpreadsheet implements BMISpreadsheet double height weight bmi public double getHeight return height ObjectEditor ABMISpreadsheet Identifier Scope Region of code where the identifier is visible Arbitrary scopes not possible Least Privilege Make scope as small as possible Scope 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 heightInMetres Scope


View Full Document

UNC-Chapel Hill COMP 14 - COMP 14 Midterm Ecam

Download COMP 14 Midterm Ecam
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view COMP 14 Midterm Ecam and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view COMP 14 Midterm Ecam and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?