Midterm Exam 2 - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Midterm Exam 2

Description:

Rationale. Why class methods? Comparison. Pros and Cons of using Class and Instance Methods ... Instance methods/constants instead of class methods/constants ... – PowerPoint PPT presentation

Number of Views:15
Avg rating:3.0/5.0
Slides: 13
Provided by: Prasun2
Learn more at: http://www.cs.unc.edu
Category:

less

Transcript and Presenter's Notes

Title: Midterm Exam 2


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

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 assetsDOLLARS_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 gt 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 lt PASS_CUTOFF true)
  • System.out.println("FAILED")
  • System.out.println("")
  • System.out.println("")
  • System.out.println("Need to take the course
    again.")
  • else
  • System.out.println("PASSED")
  • System.out.println("")
  • 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.
Write a Comment
User Comments (0)
About PowerShow.com