07ObjectOrientedProgramming

07ObjectOrientedProgramming - CSE 114 Computer Science I...

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 Thursday, 3/4 A written exam Sample exam posted to schedule page Exam Material Lectures 1 – 8 (through Iteration) HWs 1 & 2 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) && (initUpValue <= initNumFaces) ) { 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 04/13/2010 for the course CSE 114 taught by Professor Tashbook during the Spring '08 term at SUNY Stony Brook.

Page1 / 18

07ObjectOrientedProgramming - CSE 114 Computer Science I...

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