Tutorial 2

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

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

View Full Document Right Arrow Icon
CS 134 Tutorial 2: Assertions and References CS 134 Tutors Winter 2008 1
Background image of page 1

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

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

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

View Full DocumentRight Arrow Icon
True or False? (assume correct implemen- tation of method M) If the preconditions of M are not satisfied for some method call, then we know that the postconditions of M will not be satisfied. If the postconditions of M are not satisfied, then the preconditions of M were not satis- fied. If the preconditions of M are not satisfied, an error will occur. If the preconditions of M are not satisfied, the result is unpredictable. 4
Background image of page 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) { .
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online