Classes and Object-Oriented Programming in C# Computers and Programming (01204111)

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

Chapter 6 Objects and Classes F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and.
L3:CSC © Dr. Basheer M. Nasef Lecture #3 By Dr. Basheer M. Nasef.
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Arrays. Topics Tables of Data Arrays – Single Dimensional Parsing a String into Multiple Tokens Arrays - Multi-dimensional.
Computer Science 1620 Loops.
ASP.NET Programming with C# and SQL Server First Edition
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 3 Variables, Calculations, and Colors Starting Out with Games.
Introduction to Object Oriented Design. Topics Designing Your Own Classes Attributes and Behaviors Class Diagrams.
Neal Stublen Key Concepts  Classes  Objects  Inheritance  Polymorphism  Encapsulation.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
Introduction to Objects A way to create our own types.
Syllabus (1) WeekChapters 1Introduction to the course, basic java language programming concepts: Primitive Data Types and Operations 1, 2 2Methods, Control.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 8 Objects and Classes.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
STRUCT Thanachat Thanomkulabut 1. Array Review 2  Group multiple items of the same type into one "variable" double[] score; score = new.
Elements of a Java Program Bina Ramamurthy SUNY at Buffalo.
1 Advanced Issues on Classes Part 3 Reference variables (Tapestry pp.581, Horton 176 – 178) Const-reference variables (Horton 176 – 178) object sharing:
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
Agenda Object Oriented Programming Reading: Chapter 14.
1.  At the end of this slide, student able to:  Object-Oriented Programming  Research on OOP features.  Do a code walkthrough to examine the implementation.
1 Introduction to C# Programming Console applications No visual components Only text output Two types MS-DOS prompt - Used in Windows 95/98/ME Command.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
CSC241 Object-Oriented Programming (OOP) Lecture No. 4.
Chapter 8 Objects and Classes Object Oriented programming Instructor: Dr. Essam H. Houssein.
1 Interfaces and Abstract Classes Chapter Objectives You will be able to: Write Interface definitions and class definitions that implement them.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface Creating a Multiple-Form Interface.
Struct Data Type Computers and Programming ( )
Objects and Classes Mostafa Abdallah
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
IT108 Objects and Classes Part I George Mason University Revised 4/3/2012.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Objects and Classes.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 6 Objects and Classes.
C++ Class. © 2005 Pearson Addison-Wesley. All rights reserved 3-2 Abstract Data Types Figure 3.1 Isolated tasks: the implementation of task T does not.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 – Introduction to C# Programming Outline 3.1 Introduction 3.2 Simple Program: Printing a Line.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
1 Chapter 6 Programming with Objects and Classes F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive.
CS 139 Objects Based on a lecture by Dr. Farzana Rahman Assistant Professor Department of Computer Science.
Classes, Interfaces and Packages
CPS120: Introduction to Computer Science Lecture 16 Data Structures, OOP & Advanced Strings.
CSC 142 Computer Science II Zhen Jiang West Chester University
Final Review Author: Thanachat Thanomkulabut Edited by Supaporn Erjongmanee Final Review 22 September 2011.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
Introduction To Objects Oriented Programming Instructor: Mohammed Faisal.
YG - CS Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.
1 st Semester Module11 Struct Type in C# Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department.
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
VG101 RECITATION 5 By TAs. CONTENTS How to read Vg101Class.h Samples about graphics About assignment 5 Array.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
Lecture 9: Object and Classes Michael Hsu CSULA. 2 OO Programming Concepts Object-oriented programming (OOP) involves programming using objects. An object.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 4th Edition.
Lecture 3: Introduction to Object and Classes Michael Hsu CSULA.
Lecture 3: Introduction to Object and Classes Michael Hsu CSULA.
Topic: Classes and Objects
Creating Your Own Classes
Classes (Part 1) Lecture 3
Concepts of Object Oriented Programming
Two Dimensional Dynamics
Two Dimensional Dynamics
Outline Writing Classes Copyright © 2012 Pearson Education, Inc.
Chapter 3 – Introduction to C# Programming
Thanachat Thanomkulabut
Presentation transcript:

Classes and Object-Oriented Programming in C# Computers and Programming ( )

2 Outline Array revisited Array revisited Data encapsulation in C# Data encapsulation in C# Class and object creation Class and object creation Array of objects Array of objects Member methods Member methods Constructors Constructors

3 Arrays Revisited Group multiple items of the same type into one "variable" or "object" Group multiple items of the same type into one "variable" or "object" Make programming easier to manage Make programming easier to manage What if we want to keep a few things that are of different types together? What if we want to keep a few things that are of different types together? a1=3 a2=10 a0=7 a5=17 : Array a

4 Example Imagine that you have to write a program Imagine that you have to write a program  To store 100 students' names  That's simple; just use an array ...and their scores  Also simple; create another array ...and also their ID, department, faculty, advisor, etc using System; class Scoring { public static void Main() { string [] name = new string[100]; double [] score = new double[100]; : } using System; class Scoring { public static void Main() { string [] name = new string[100]; double [] score = new double[100]; : }

5 More Example From the previous slide: From the previous slide:  We want to store students' ID, name, score, department, faculty, advisor, etc  We could write a program like this: using System; class Scoring { public static void Main() { string [] name = new string[100]; int [] ID = new int[100]; double [] score = new double[100]; string [] dept = new string[100]; string [] faculty = new string[100]; string [] advisor = new string[100]; : } using System; class Scoring { public static void Main() { string [] name = new string[100]; int [] ID = new int[100]; double [] score = new double[100]; string [] dept = new string[100]; string [] faculty = new string[100]; string [] advisor = new string[100]; : } What a mess...

6 Data Encapsulation A mechanism that bundles multiple items of varying types into one item or "object" A mechanism that bundles multiple items of varying types into one item or "object" Dept="ME" Advisor="Arthur" Name="Paula" ID= Paula ME Arthur ID: Name: Dept: Advisor: Object studentInfo

7 Encapsulation in C# C# provides two kinds of data encapsulation: struct and class C# provides two kinds of data encapsulation: struct and class  This course will focus on classes only Objects created from a class can store a fixed number of items Objects created from a class can store a fixed number of items  may be of different types A class is defined by programmer A class is defined by programmer

8 Using Class 1.Define a class 2.Create an object from the class 3.Access data in the object

9 Defining Class class StudentInfo { public int id; public string name; public string dept; } class StudentInfo { public int id; public string name; public string dept; } Must use "class" keyword Every class needs a name Members (or properties) of objects to be created Protection level – always use "public" for now

10 Defining Class (cont'd) Where do we put the class definition? Where do we put the class definition?  Inside or outside a class  Outside a method E.g., E.g., using System; class Test { class StdInfo { public int id; public string name; public string dept; } public static void Main() { : } using System; class Test { class StdInfo { public int id; public string name; public string dept; } public static void Main() { : } using System; class StdInfo { public int id; public string name; public string dept; } class Test { public static void Main() { : } using System; class StdInfo { public int id; public string name; public string dept; } class Test { public static void Main() { : } or

11 Creating Object from Class Syntax: Syntax: or or Example: Example: class-name obj-name = new class-name(); using System; class Test { class StdInfo { public int id; public string name; public string dept; } public static void Main() { StdInfo student = new StdInfo(); : } using System; class Test { class StdInfo { public int id; public string name; public string dept; } public static void Main() { StdInfo student = new StdInfo(); : } class-name obj-name; obj-name = new class-name(); class-name obj-name; obj-name = new class-name();

12 Computer Memory Object Creation Process StdInfo student; student = new StdInfo(); StdInfo student; student = new StdInfo(); ?? just a reference, not an actual object ? ? ? ? ID: Name: Dept: Advisor: Object studentInfo student

13 Accessing Object's Members Syntax: Syntax: Example: Example: obj-name.member-name using System; class Test { class StdInfo { public int id; public string name; public string dept; } public static void Main() { StdInfo student = new StdInfo(); student.id = ; student.name = "Paula"; student.dept = "ME"; Console.WriteLine("ID: {0}", student.id); } using System; class Test { class StdInfo { public int id; public string name; public string dept; } public static void Main() { StdInfo student = new StdInfo(); student.id = ; student.name = "Paula"; student.dept = "ME"; Console.WriteLine("ID: {0}", student.id); }

14 Array of Objects Array of integers Array of integers Object of type StdInfo (with reference variable) Object of type StdInfo (with reference variable) Array of (references to) objects of type StdInfo Array of (references to) objects of type StdInfo Paula ME ID: Name: Dept: Lisa EE ID: Name: Dept: Uma CPE ID: Name: Dept: Paula ME ID: Name: Dept: obj-var

15 Creating Array of Objects Syntax: Syntax: Example: Example: class-name[] array-name = new class-name[size]; using System; class Test { class StdInfo { public int id; public string name; public string dept; } public static void Main() { StdInfo [] students = new StdInfo[50]; for (int i = 0; i < 50; i++) students[i] = new StdInfo(); : } using System; class Test { class StdInfo { public int id; public string name; public string dept; } public static void Main() { StdInfo [] students = new StdInfo[50]; for (int i = 0; i < 50; i++) students[i] = new StdInfo(); : } Create an array for storing 50 references to StdInfo objects Create an actual object StdInfo for each reference in the array

16 Accessing Objects in Array Syntax: Syntax: Example: Example:  Set Student#2's name to "Ariya"  Display Student#3's department array-name[index].member students[2].name = "Ariya"; Console.WriteLine("Department: {0}", students[3].dept);

17 Accessing Details class StdInfo { public int ID; public string Name; public string Dept; } static void Main() { StdInfo[] students; students = new StdInfo[4]; : students[2].Name = "Ariya"; } class StdInfo { public int ID; public string Name; public string Dept; } static void Main() { StdInfo[] students; students = new StdInfo[4]; : students[2].Name = "Ariya"; } Paula ENVE ID: Name: Dept: Lisa ME ID: Name: Dept: Uma CPE ID: Name: Dept: Masha EE ID: Name: Dept: Ariya

18 Example: Student Records Get N students' information with 3 fields Get N students' information with 3 fields  ID, Name, Score Then output a table of information Then output a table of information First, we define a class as shown: First, we define a class as shown: class StdInfo { public int id; public string name; public int score; } class StdInfo { public int id; public string name; public int score; }

19 ReadInfo Method Reads all information for each student Reads all information for each student Returns an object of class StdInfo Returns an object of class StdInfo static StdInfo ReadInfo() { StdInfo info = new StdInfo(); Console.Write("ID: "); info.id = int.Parse(Console.ReadLine()); Console.Write("Name: "); info.name = Console.ReadLine(); Console.Write("Score: "); info.score = int.Parse(Console.ReadLine()); return info; } static StdInfo ReadInfo() { StdInfo info = new StdInfo(); Console.Write("ID: "); info.id = int.Parse(Console.ReadLine()); Console.Write("Name: "); info.name = Console.ReadLine(); Console.Write("Score: "); info.score = int.Parse(Console.ReadLine()); return info; }

20 ShowInfo Method Takes a StdInfo and displays the information on screen Takes a StdInfo and displays the information on screen Returns nothing Returns nothing static void ShowInfo(StdInfo info) { Console.WriteLine("{0,3} {1,-10} {2,2}", info.id, info.name, info.score); } static void ShowInfo(StdInfo info) { Console.WriteLine("{0,3} {1,-10} {2,2}", info.id, info.name, info.score); }

21 Put Them All Together using System; class StdRecords { // Define class StdInfo here // Define ReadInfo() here // Define ShowInfo() here static void Main() { Console.Write("How many students? "); int n = int.Parse(Console.ReadLine()); StdInfo[] students = new StdInfo[n]; for (int i = 0; i < n; i++) students[i] = ReadInfo(); for (int i = 0; i < n; i++) ShowInfo(students[i]); } using System; class StdRecords { // Define class StdInfo here // Define ReadInfo() here // Define ShowInfo() here static void Main() { Console.Write("How many students? "); int n = int.Parse(Console.ReadLine()); StdInfo[] students = new StdInfo[n]; for (int i = 0; i < n; i++) students[i] = ReadInfo(); for (int i = 0; i < n; i++) ShowInfo(students[i]); }

22 Object-Oriented Programming Classes are more than just a mechanism to bundle data into objects Classes are more than just a mechanism to bundle data into objects Objects may have its own behaviors (defined by classes) to perform on its properties Objects may have its own behaviors (defined by classes) to perform on its properties  E.g., they know how to display their data on screen, or compute their properties  E.g., every circle object knows how to calculate its area These are the concepts of Object-Oriented Programming (OOP) These are the concepts of Object-Oriented Programming (OOP)

23 Object-Oriented View of Classes A class serves like a template to create objects of the same type A class serves like a template to create objects of the same type  A class defines a list of properties its objects must have, but does not specify the values of these properties Class Circle Properties: radius, color create create create circle1 color = Yellow radius = 1 circle2 color = Red radius = 1.5 circle3 color = Blue radius = 2 objects of class Circle

24 OOP and Graphical User Interface GUI components we have seen are objects of some classes GUI components we have seen are objects of some classes  E.g., buttons are objects of class Button inside System.Windows.Forms namespace button1.Left = 60 button1.Top = 31 button1.Height = 56 button1.Width = 115 button1.Text = "OK" button2.Left = 144 button2.Top = 127 button2.Height = 75 button2.Width = 23 button2.Text = "Cancel" button2.Color = Color.Red

25 Member Methods Class may contain methods Class may contain methods  Allow objects to perform computation on its own data  Known as member methods Each member method can access other members inside the same object Each member method can access other members inside the same object

26 Example: Member Methods Consider the following Person class Consider the following Person class We can add a GetAge method to the class to calculate a person’s age We can add a GetAge method to the class to calculate a person’s age class Person { public string name; public int birth_year; } class Person { public string name; public int birth_year; } class Person { public string name; public int birth_year; public int GetAge() { return 2010 – birth_year; } class Person { public string name; public int birth_year; public int GetAge() { return 2010 – birth_year; } In real program, 2010 should not be hard-coded like this!

27 Thinking Corner Add two methods, Circumference and Area, into the Circle class below Add two methods, Circumference and Area, into the Circle class below  So that each Circle object knows how to compute its own circumference length and area class Circle { public double radius; public double Circumference() { : } public double Area() { : } class Circle { public double radius; public double Circumference() { : } public double Area() { : }

28 Constructors A constructor is a special member method defined in a class A constructor is a special member method defined in a class  It allows us to specify how each object of this class gets constructed  It’s a method with the same name as the class and without return type (not even void) E.g., E.g., class Person { public string name; public int birth_year; public Person() { birth_year = 1975; } class Person { public string name; public int birth_year; public Person() { birth_year = 1975; } Person p = new Person(); Console.WriteLine(p.birth_year); Person p = new Person(); Console.WriteLine(p.birth_year);

29 Constructors with Parameters A constructor may also be defined to accept parameters A constructor may also be defined to accept parameters E.g., E.g., class Person { public string name; public int birth_year; public Person(string s) { name = s; birth_year = 1975; } class Person { public string name; public int birth_year; public Person(string s) { name = s; birth_year = 1975; } Person p = new Person("John"); Console.WriteLine(p.name); Console.WriteLine(p.birth_year); Person p = new Person("John"); Console.WriteLine(p.name); Console.WriteLine(p.birth_year); The new operation passes the parameter to the newly created object

30 Referencing Members In the previous example, the parameter name s in the constructor is not so meaningful, so we change it to name In the previous example, the parameter name s in the constructor is not so meaningful, so we change it to name class Person { public string name; public int birth_year; public Person(string name) { name = name; birth_year = 1975; } class Person { public string name; public int birth_year; public Person(string name) { name = name; birth_year = 1975; } Does nothing because both 'name's refer to the parameter of the constructor

31 Referencing Members: this Variable To make a reference to the current object, the special keyword this can be used To make a reference to the current object, the special keyword this can be used class Person { public string name; public int birth_year; public Person(string name) { this.name = name; this.birth_year = 1975; } class Person { public string name; public int birth_year; public Person(string name) { this.name = name; this.birth_year = 1975; }

32 Thinking Corner Add a constructor to the Circle class so that its objects can be created with provided 'radius' parameter Add a constructor to the Circle class so that its objects can be created with provided 'radius' parameter class Circle { public double radius; } class Circle { public double radius; } static void Main() { Circle c1 = new Circle(30); Circle c2 = new Circle(2.5); } static void Main() { Circle c1 = new Circle(30); Circle c2 = new Circle(2.5); }

33 Example: Balls in 2D Space (1) Let us write a program (OOP style) to simulate ball movement in 2D space Let us write a program (OOP style) to simulate ball movement in 2D space  Each ball knows its own current acceleration and velocity (on both x- and y-axes)  Each ball knows its current position (x,y)  Each ball knows how to update its position and velocity after time t (seconds) has passed  Assuming constant acceleration (x,y) v = (vx,vy) a = (ax,ay)(x,y) v = (vx,vy) 3 seconds passed (0,0) + +

34 Example: Balls in 2D Space (2) Let us define the class Ball so that each Ball object has the following properties: Let us define the class Ball so that each Ball object has the following properties:  double sx,sy – current position on the x- and y- axes (in meters)  double vx,vy – current velocity on the x- and y- axes (in m/s)  double ax,ay – current acceleration on the x- and y- axes (in m/s 2 ) class Ball { public double sx, sy; public double vx, vy; public double ax, ay; } class Ball { public double sx, sy; public double vx, vy; public double ax, ay; }

35 Example: Balls in 2D Space (3) Add a method Update to update the position and velocity of the ball Add a method Update to update the position and velocity of the ball  High school physics applies here class Ball { : public void Update(double t) // t = time elapsed { sx = sx + 0.5*ax*t*t + vx*t; sy = sy + 0.5*ay*t*t + vy*t; vx = vx + ax*t; vy = vy + ay*t; } class Ball { : public void Update(double t) // t = time elapsed { sx = sx + 0.5*ax*t*t + vx*t; sy = sy + 0.5*ay*t*t + vy*t; vx = vx + ax*t; vy = vy + ay*t; }

36 Example: Balls in 2D Space (4) Finally, add a constructor to allow convenient creation of Ball objects Finally, add a constructor to allow convenient creation of Ball objects class Ball { : public Ball(double sx, double sy, double vx, double vy, double ax, double ay) { this.sx = sx; this.sy = sy; this.vx = vx; this.vy = vy; this.ax = ax; this.ay = ay; } class Ball { : public Ball(double sx, double sy, double vx, double vy, double ax, double ay) { this.sx = sx; this.sy = sy; this.vx = vx; this.vy = vy; this.ax = ax; this.ay = ay; }

37 Example: Balls in 2D Space (5) Test the program Test the program Simulate two Ball objects Simulate two Ball objects  Ball b1 moves at constant velocity (ax = ay = 0)  Ball b2 moves under Earth's gravity (ax = 0, ay = 9.8) static void Main() { Ball b1 = new Ball(0,0,10,20,0,0); Ball b2 = new Ball(0,100,0,0,0,-9.8); b1.Update(10); b2.Update(10); Console.WriteLine("After 10 seconds…"); Console.Write("b1 is at position ({0},{1})", b1.sx, b1.sy); Console.WriteLine(" with velocity [{0} {1}]", b1.vx, b1.vy); Console.Write("b1 is at position ({0},{1})", b2.sx, b2.sy); Console.WriteLine(" with velocity [{0} {1}]", b2.vx, b2.vy); } static void Main() { Ball b1 = new Ball(0,0,10,20,0,0); Ball b2 = new Ball(0,100,0,0,0,-9.8); b1.Update(10); b2.Update(10); Console.WriteLine("After 10 seconds…"); Console.Write("b1 is at position ({0},{1})", b1.sx, b1.sy); Console.WriteLine(" with velocity [{0} {1}]", b1.vx, b1.vy); Console.Write("b1 is at position ({0},{1})", b2.sx, b2.sy); Console.WriteLine(" with velocity [{0} {1}]", b2.vx, b2.vy); }

38 Example: Projectile Motion (1) Simulate projectile motion on earth Simulate projectile motion on earth  Cannon ball exits the cannon at position (0,0)  Ask user for initial velocity  Report the position of the cannon ball every second v = (50,50) a = (0,-9.8)

39 Example: Projectile Motion (2) static void Main() { Console.Write("Enter initial vx: "); double vx = double.Parse(Console.ReadLine()); Console.Write("Enter initial vy: "); double vy = double.Parse(Console.ReadLine()); Ball b = new Ball(0, 0, vx, vy, 0, -9.8); Console.WriteLine("Time sx sy vx vy"); Console.WriteLine(" "); for (int i = 0; i <= 10; i++) // simulate for 10 seconds { Console.WriteLine("{0,2}{1,8:f2}{2,8:f2}{3,8:f2}{4,8:f2}", i, b.sx, b.sy, b.vx, b.vy); b.Update(1); } Console.ReadLine(); } static void Main() { Console.Write("Enter initial vx: "); double vx = double.Parse(Console.ReadLine()); Console.Write("Enter initial vy: "); double vy = double.Parse(Console.ReadLine()); Ball b = new Ball(0, 0, vx, vy, 0, -9.8); Console.WriteLine("Time sx sy vx vy"); Console.WriteLine(" "); for (int i = 0; i <= 10; i++) // simulate for 10 seconds { Console.WriteLine("{0,2}{1,8:f2}{2,8:f2}{3,8:f2}{4,8:f2}", i, b.sx, b.sy, b.vx, b.vy); b.Update(1); } Console.ReadLine(); } Enter initial vx: 50 Enter initial vy: 50 Time sx sy vx vy Format the value to have 2 decimal places and width of 8 characters

40 Thinking Corner Modify the program in the previous example to ask user for starting speed and angle of the cannon ball, instead of vx,vy Modify the program in the previous example to ask user for starting speed and angle of the cannon ball, instead of vx,vy  s

41 Challenging Corner Write a GUI application that creates several Ball objects, then simulates their movements and draw them on a window Write a GUI application that creates several Ball objects, then simulates their movements and draw them on a window  Use a Timer to update the time and draw the balls at new locations  Make balls bounce when they hit walls

42 Conclusion Multiple related data items can be bundled into an object by defining a class for it Multiple related data items can be bundled into an object by defining a class for it Object-Oriented Programming (OOP) allows programmers to view data as objects that have their own behaviors Object-Oriented Programming (OOP) allows programmers to view data as objects that have their own behaviors