Tutorial 2

# Tutorial 2 - CS 134 Tutorial 2 Assertions and References CS...

This preview shows pages 1–6. Sign up to view the full content.

CS 134 Tutorial 2: Assertions and References CS 134 Tutors Winter 2008 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Welcome to Tutorial 2 Announcements Today’s agenda Assertions (inline, preconditions, postcon- ditions) References and memory allocation in Java 2
Preconditions and Postconditions Preconditions and postconditions: a contract preconditions satisﬁed + correct implementa- tion postconditions satisﬁed Pay attention to parameter/return types What if no precondition is given? Example: IntegerMatrix class 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
True or False? (assume correct implemen- tation of method M) If the preconditions of M are not satisﬁed for some method call, then we know that the postconditions of M will not be satisﬁed. If the postconditions of M are not satisﬁed, then the preconditions of M were not satis- ﬁed. If the preconditions of M are not satisﬁed, an error will occur. If the preconditions of M are not satisﬁed, the result is unpredictable. 4
1 Assertions 1.1 Preconditions and Postconditions Listed below is a Java class (methods unimplemented) called IntegerMatrix . Write clear and precise preconditions and postconditions for the methods in the class below. /* This is a class to represent a matrix of integers. Note that rows are numbered 1 through M from top to bottom and columns are numbered 1 through N from left to right. */ public class IntegerMatrix { public void setEntry(int i, int j, int value) { . .. } public int getEntry(int i, int j) { . .. } public int getNumCols() { . .. } public int getNumRows() { . .. } public IntegerMatrix plus(IntegerMatrix other) { . .. } public IntegerMatrix scalarMult(int c) { .

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 01/25/2010 for the course CS CS134 taught by Professor Cl during the Fall '07 term at Waterloo.

### Page1 / 12

Tutorial 2 - CS 134 Tutorial 2 Assertions and References CS...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online