L7 - CSE 114 Computer Science I Object Oriented Programming...

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

View Full Document Right Arrow Icon
CSE 114 – Computer Science I Object Oriented Programming Signal Hill, Newfoundland
Background image of page 1

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

View Full DocumentRight Arrow Icon
Midterm 1 • Friday, 3/11 • A written exam • Sample exam will be posted to webpage • Exam Material – Lectures 1 – 9 (through Iteration, notes L1 to L5.pdf) – Labs 1 – 8
Background image of page 2
Die Object STATE (What information describes it?) •Number of Faces – maximum numbers on dice •Value facing up – number on upward face BEHAVIOR (What can we do with it?) •Initialize – initializes state •Roll – choose a random up-face value •Read the value – get current up-face value
Background image of page 3

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

View Full DocumentRight Arrow Icon
Constructors (revisited) Another constructor for Die: public Die(int initNumFaces, int initUpValue) { if ( (initUpValue > 0) && (initNumFaces >= 4) ) { numFaces = initNumFaces; upValue = initUpValue; } } Original (default) constructor for Die: public Die() { numFaces = 6; upValue = 1; } Our second constructor for Die: public Die(int faces) { numFaces = faces; upValue = 1; }
Background image of page 4
More on Constructors • The Die class can have ALL THREE constructors! • How does the compiler know which one to run? Die die1 = new Die(); Die die2 = new Die(20); Die die3 = new Die(8,3);
Background image of page 5

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

View Full DocumentRight Arrow Icon
More on Constructors (cont’d) • The constructor that is executed depends on: – the number of parameters – the types of the parameters – the order of the parameters • Called the method signature • If no constructor is given in a class, the Java compiler adds an empty constructor with no parameters: public void Die() { }
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/29/2011 for the course CSE 114 taught by Professor Tashbook during the Spring '08 term at SUNY Stony Brook.

Page1 / 19

L7 - CSE 114 Computer Science I Object Oriented Programming...

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

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