Presentation is loading. Please wait.

Presentation is loading. Please wait.

Midterm Exam 2 75 points 1 min per point Allocate time proportionate to points Closed book Chapters 6-9 Look at exercises.

Similar presentations


Presentation on theme: "Midterm Exam 2 75 points 1 min per point Allocate time proportionate to points Closed book Chapters 6-9 Look at exercises."— Presentation transcript:

1 Midterm Exam 2 75 points 1 min per point Allocate time proportionate to points Closed book Chapters 6-9 Look at exercises

2 Exam Question Difficulty Obvious questions Questions requiring studying Challenging questions Hardness of exam proportional to hardness of assignments

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

4 Essay Questions Definitions –Define class method. Distinction –Distinguish class and instance methods. Rationale –Why class methods? Comparison –Pros and Cons of using Class and Instance Methods

5 Understanding Code Identify Errors –Class Vs Interfaces as Types –Static Vs instance methods/constants/variables –Off-by-one errors –Infinite loops –Null pointers –….

6 Understanding Code Identify Style Principle Violations –Class as Types –Instance methods/constants instead of class methods/constants –Code duplication in If-Else –No separation of Concerns –Side Effects –...

7 Understanding Code Identify Errors & Style Violations public interface Money { public int getPounds(); public int getDollars(); public int DOLLARS_IN_LB = 1.8; } public class PoundMoney implements Money { static int assets; public static int getPounds() { return assets; } public int getDollars() { return assets*DOLLARS_IN_LB; } }

8 Understanding Code Characterize Code –Overloaded & Polymorphic Methods –Static & Instance Variables –Logical & Physical Structure –Counter & Event-controlled loops –Side Effects –...

9 Understanding Code Trace execution (explain output) of programs involving –Conditionals –Loops –Class/instance variables –Constructors –main method

10 Understanding Code (example) What is the output of the following loops, when n is (i) 4 and (ii) –4. a) while (n >= 0) { n = n –1; System.out.println (n); } b) while (n != 0) { n = n –1; System.out.println (n); }

11 Writing Code Improve Code by removing style principle violations. E.g: public void fancyPrintGrade(int score) { if (score < PASS_CUTOFF == true) { System.out.println("FAILED"); System.out.println("**************"); System.out.println("Need to take the course again."); } else { System.out.println("PASSED"); System.out.println("**************"); System.out.println("Congratulations!"); }

12 Writing Code Write Functions/Procedures/Main Methods/Classes Involving –Loops, Conditionals, Static Vars,... –E.g: Write a program that prints all positive odd numbers less than some limit n.


Download ppt "Midterm Exam 2 75 points 1 min per point Allocate time proportionate to points Closed book Chapters 6-9 Look at exercises."

Similar presentations


Ads by Google