07ObjectOrientedProgramming

07ObjectOrientedProgramming - CSE 114 Computer Science I...

Info icon This 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
Image of page 1

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

View Full Document Right 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
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
Image of page 3

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

View Full Document Right 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; }
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);
Image of page 5

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

View Full Document Right 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() { }
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern