Teaching%20Session%208

Teaching Session%2 - Engineering 1D04 Teaching Session 8 © Copyright 2006 David Das Ryan Lortie Alan Wassyng 1 Recap HighScores Example txtName1

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Engineering 1D04 Teaching Session 8 © Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 1 Recap: HighScores Example txtName1 txtName2 txtScore2 txtScore1 © Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 2 recap: HighScores Example public class HighScore { private class hsRecord { public string name; public int score; } private const int maxElements = 10; private hsRecord hsArray = new hsRecord[maxElements]; private int length; public bool add(string newName, int newScore) { . . . } public void show() { . . . } } no room to show this here no room to show this here © Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 3 recap: HighScores s What about including a title for the name of the game at the time of instantiation? s In general it is useful to be able to include initial processing for an object at the time of its instantiation. s This is done through a constructor . © Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 4 Constructors s A constructor is simply a method that is executed automatically when the class is instantiated in an object. s The name of the constructor method is exactly the same as the name of the class. s The constructor method may also include parameters. © Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 5 A Constructor for HighScores s Consider our example. We want the constructor to include a string parameter for the title of the game. © Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 6 Constructor Example public class HighScore { private class hsRecord { public string name; public int score; } const int maxElements = 10; private hsRecord hsArray = new hsRecord[maxElements]; private int length = 0; private string result; private string hsTitle; public HighScore(string title) { hsTitle = title; } . . ....
View Full Document

This note was uploaded on 12/05/2010 for the course MATH 1Z04 taught by Professor Childs during the Spring '08 term at McMaster University.

Page1 / 26

Teaching Session%2 - Engineering 1D04 Teaching Session 8 © Copyright 2006 David Das Ryan Lortie Alan Wassyng 1 Recap HighScores Example txtName1

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

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