Using Classes1 Using Existing Classes Random CTEC2902 Advanced Programming.

Slides:



Advertisements
Similar presentations
CS0004: Introduction to Programming Select Case Statements and Selection Input.
Advertisements

Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Fields, Constructors, Methods
CTEC2902 Advanced Programming in Visual Studio (ASP. NET + C#
Generics and the ArrayList Class
Aalborg Media Lab 2-May-15 Exercises/Summary Lecture 10 Summary, Exercises.
CHAPTER 9 DEFINING CLASSES & CREATING OBJECTS Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
CS 180 Problem Solving and Object Oriented Programming Fall 2011 Notes for Week 4: September 12-16, 2011 Aditya Mathur/Tim Korb Department of Computer.
CPSC150 Week 6 notes Chapter 5 and other topics. toString Try to print any class Many print “garbage” (e.g., an address) All classes inherit from Object.
Summary of text to be covered Create your own class Create and use objects of your own class Control access to object instance variables Use keyword private.
Slides prepared by Rose Williams, Binghamton University Chapter 14 Generics and the ArrayList Class.
CTEC2902 Adv Programming CTEC2902 Advanced Programming in Visual Studio ( ASP.NET + VB.NET + ADO.NET) Tugrul Essendal 1.
CS100J 11 September 2003 Course Management System for CS100J is now populated with students who were pre-registered. Look at course web page to see how.
Object-Oriented Application Development Using VB.NET 1 Creating a String Array Code to create a String array: ' declare a String array with 4 elements.
Java Library Java provides a huge library or collection of useful programs A gold mine of well-tested code that can save you countless hours of development.
Chapter 14 Generics and the ArrayList Class Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Objects & Object-Oriented Programming (OOP) CSC 1401: Introduction to Programming with Java Week 15 – Lecture 1 Wanda M. Kunkle.
Week 5 Recap CSE 115 Spring Composition Informally called “has a” Represented in UML with a diamond- headed arc In code: Declare an instance variable.
Intro to ADO.NET1 CTEC2902 Advanced Programming Introduction to ActiveX Data Objects.NET (.NET Class Library for Database Processing)
CS1101: Programming Methodology Aaron Tan.
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
Neal Stublen Overview of.NET Windows Applications Microsoft Windows OS / Intel Platform Windows Application File SystemNetworkDisplay.
Using Object-Oriented JavaScript CST 200- JavaScript 4 –
Com1040 Systems Design and Testing Part II – Testing (Based on A.J. Cowling’s lecture notes) LN-Test3: Equivalence classes and boundary conditions Marian.
Turtle Graphics Victor Norman CS104 Calvin College.
1 Lesson 6 — Database Programming Microsoft Visual Basic.NET, Introduction to Programming.
Chapter 8: Writing Graphical User Interfaces
8-1 Chapter 8 Using User-Defined Data Types and Object Oriented Programming.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
PROGRAMMING Functions. Objectives Understand the importance of modular programming. Know the role of functions within programming. Use functions within.
Object Oriented Design: Identifying Objects
Variables "There are 10 kinds of people in the world today – those who understand binary and those who don't!” Unknown.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Classes and Objects noun A word used to denote or name a person, place, thing, quality, or act. verb That part of speech that expresses existence,
JavaScript, Fourth Edition
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
1 Week 2: Variables and Assignment Statements READING: 1.4 – 1.6 EECS Introduction to Computing for the Physical Sciences.
Week 2 Lab2 Practice Dina A. Said
Applications Development
Session 16 Pinball Game Construction Kit:. Pinball Version 1 Replaced the fire button with a mouse event. Multiple balls can be in the air at once. –Uses.
Aug 9, CMSC 202 ArrayList. Aug 9, What’s an Array List ArrayList is  a class in the standard Java libraries that can hold any type of object.
1 Working with Data Structures Kashef Mughal. 2 Chapter 5  Please review on your own  A few terms .NET Framework - programming model  CLR (Common.
1 Advanced Computer Programming Lab Calculator Project.
Module 8: Creating User Controls. Overview Adding User Controls to an ASP.NET Web Form Creating User Controls.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
1.
Object-Oriented Application Development Using VB.NET 1 Chapter 10 VB.NET GUI Components Overview.
Lesson 6 – Libraries & APIs Libraries & APIs. Objective: We will explore how to take advantage of the huge number of pre-made classes provided with Java.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Object-Based Programming in VB.NET. Must Understand Following: Encapsulation Information hiding Abstract Data Type Class, Instance, Reference Variable.
Chapter 8 Searching and Sorting © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Libraries and APIs Don’t reinvent the wheel. What’s an API? API – Application Programmers Interface –We want to use code someone else has written –API’s.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Flashcard Quiz Program BY: KISHIN ARUWANI. Background  This program will be created as a studying tool to give students the ability to create flashcards.
Chapter 13 Copyright 2000 All rights reserved 1 Chapter 13 Object-Oriented Programming.
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
ILM Proprietary and Confidential -
An Introduction to Programming with C++ Fifth Edition Chapter 14 Classes and Objects.
Coding – Week 2 Functions, Arrays, and Objects. Functions  Functions are not a new concept – you’ve been using them already.  void setup() {} and void.
CONDITIONALS CITS1001. Scope of this lecture if statements switch statements Source ppts: Objects First with Java - A Practical Introduction using BlueJ,
Programming Right from the Start with Visual Basic .NET 1/e
Interfaces.
Chapter 11 – Object-Oriented Programming
Object-oriented design for multiple classes
Symbolism. Symbolism anything that is associated with and hints at something else. In Life… A UNIVERSAL symbol is: anything that is associated with.
Week 3 Object-based Programming: Classes and Objects
Using Functions
Tonga Institute of Higher Education
Which best describes the relationship between classes and objects?
Hints on Chapter 5.
Presentation transcript:

Using Classes1 Using Existing Classes Random CTEC2902 Advanced Programming

The story so far... You know What an object is What a class is The relationship between classes and objects Let’s carry on… CTEC2902 Advanced Programming 2Using Classes

3 How to Use An Existing Class Step 1 – Create an object instance of the class Dim instance_name As New class_name Name of class you want to use Your identifier for your object (meaningful name) Must already exist MUST have this keyword (called a constructor)

Using Classes4 The object Rambo has all the properties and methods of class Random How to Use An Existing Class Step 1 – Create an object instance of the class E.g. Dim Rambo As New Random butwhat is Random? What service does it provide? what are its properties and methods? how can we use its services? Answer: you need to read API of Random

Using Classes5 Application Programmers’ Interface An API must explain Service provided Namespace Class name Inherited classes Constructors Public Properties Public Methods

Using Classes6 Using Classes – Example(for lab exercises) VB.NET built-in random number generator Class name:Random Method name:Next (Min, Max) for integer values Returns a random value, where... Min <= Value < Max

Using Classes7 Example - Using Classes Set a variable to a random value in the range 0-9 ‘Create a random number-generating object Dim Generator As New Random ‘Create a variable to hold the random value Dim MyRandomDigit As Integer ‘Generate a random value & save it MyRandomDigit = Generator.Next (0, 10) Your variable now holds a value between 0 and 9, inclusive

Using Classes8 Exercise – Random Class Generate 2 random numbers, in the range 10-50, show the larger of the two in the text box txtBig Dim Fred As New Random Dim First As Integer, Second As Integer First = Fred.Next (10, 51) Second = Fred.Next (10, 51) If First > Second Then txtBig.Text = First Else txtBig.Text = Second End If

Using Classes9 Exercise – Random Class Generate 100 random integer values, between 0 and 500, and place them in a list box list, named lstFred D im Randomizer As New Random, Val As Integer Dim I As Integer For I = 1 To 100 Val = Randomizer.Next(0, ) lstFred.Items.Add (Val) Next

Using Classes10 Exercise – Random Class Generate 1000 random integer values, between 0 and 100, and place them in an array list, named Bob Dim Bob As New ArrayList Dim Randomizer As New Random, Val As Integer Dim I As Integer For I = 1 To 1000 Val = Randomizer.Next(0, ) Bob.Add (Val) Next

Using Classes11Exercises11 Hint: the best way to see what an object offers, in the way of properties and classes, is to type in a dot after object name and scroll the list box that appears as a result If the list box does not appear when you type in a dot, then something is wrong – your object is not recognised as an object by.NET

Using Classes12 Summary To create an object instance of a class Dim object_name As New class_name To set or get property values of an object a)To setobject_name.property_name = Source b)To getTarget = object_name.property_name To use methods of an object object_name.method_name (optional parameters) Note the full stops Object properties behave like variables; i.e., Have data types Store values Values may change Object methods behave like procedures; i.e., Each one performs an action May need parameters May return data

Using Classes13 Any questions? More objects & classes next week