Week 11 - Friday.  What did we talk about last time?  Object methods  Accessors  Mutators  Constructors  Defining classes.

Slides:



Advertisements
Similar presentations
Composition CMSC 202. Code Reuse Effective software development relies on reusing existing code. Code reuse must be more than just copying code and changing.
Advertisements

Objected Oriented Perl An introduction – because I don’t have the time or patience for an in- depth OOP lecture series…
Written by: Dr. JJ Shepherd
Week 11: Class Design 1.  Most classes are meant to be used more than once  This means that you have to think about what will be helpful for future.
Week 10: Objects and Classes 1.  There are two classifications of types in Java  Primitive types:  int  double  boolean  char  Object types: 
Chapter 14: Overloading and Templates
Stacks.
1. 2 Introduction to Methods  Method Calls  Parameters  Return Type  Method Overloading  Accessor & Mutator Methods  Student Class: Revisited.
Chapter 101 Dynamic Data Structures and Generics Chapter 10.
CS 106 Introduction to Computer Science I 03 / 21 / 2008 Instructor: Michael Eckmann.
ECE122 L6: Problem Definition and Implementation February 15, 2007 ECE 122 Engineering Problem Solving with Java Lecture 6 Problem Definition and Implementation.
Loops We have been using loops since week 2, our void draw(){ } is a loop A few drawbacks of draw() –It is endless –There is only one draw() –It updates.
Slide 1. Slide 2 Administrivia Nate's office hours are Wed, 2-4, in 329 Soda! TA Clint will be handing out a paper survey in class sometime this week.
COMP 110 Information Hiding and Encapsulation Tabitha Peck M.S. February 25, 2008 MWF 3-3:50 pm Philips
More C++ Bryce Boe 2013/07/18 CS24, Summer 2013 C.
Week 10 - Monday.  What did we talk about last time?  Method overloading  Lab 9.
UML Basics & Access Modifier
Comp 248 Introduction to Programming Chapter 4 - Defining Classes Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Question of the Day  What card(s) must you flip to verify the following statement: Cards with a vowel on one side, have an even number on the other side.
Week 13 - Wednesday.  What did we talk about last time?  Color representation  Color class  Picture class.
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments.
Creating Simple Classes. Outline of Class Account Class Account Account # Balance Holder name phone# Overdrawn (true/false) Data Members Open Credit Debit.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
CS 106 Introduction to Computer Science I 03 / 19 / 2007 Instructor: Michael Eckmann.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
Review of ICS 102. Lecture Objectives To review the major topics covered in ICS 102 course Refresh the memory and get ready for the new adventure of ICS.
DATA STRUCTURES LAB 1 TA: Nouf Al-harbi
Week 9 - Monday.  What did we talk about last time?  Time  GDB.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
CSSE501 Object-Oriented Development. Chapter 4: Classes and Methods  Chapters 4 and 5 present two sides of OOP: Chapter 4 discusses the static, compile.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
CSC 142 Computer Science II Zhen Jiang West Chester University
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Types and Interfaces COMP.
CS305j Introduction to Computing Classes 1 Topic 23 Classes – Part I "A 'class' is where we teach an 'object' to behave." -Rich Pattis Based on slides.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
EGR 2261 Unit 11 Classes and Data Abstraction  Read Malik, Chapter 10.  Homework #11 and Lab #11 due next week.  Quiz next week.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Arithmetic, Class Variables and Class Methods Week 11
Week 13 - Wednesday.  What did we talk about last time?  Color representation  Color class  Picture class.
Week 11 - Friday.  What did we talk about last time?  Object methods  Accessors  Mutators  Constructors  Defining classes.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Types and Interfaces COMP.
Week 12 - Friday.  What did we talk about last time?  Finished hunters and prey  Class variables  Constants  Class constants  Started Big Oh notation.
Topic 8Classes, Objects and Methods 1 Topic 8 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference Classes, Objects,
Week 12 - Wednesday.  What did we talk about last time?  Hunters and prey.
Written by: Dr. JJ Shepherd
Week 12 - Monday.  What did we talk about last time?  Defining classes  Class practice  Lab 11.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
Week 10 - Wednesday.  What did we talk about last time?  Method example  Roulette simulation  Types in Java.
CS 106 Introduction to Computer Science I 03 / 22 / 2010 Instructor: Michael Eckmann.
Week 10 - Monday.  What did we talk about last time?  Method overloading  Lab 9.
Non-Static Classes What is the Object of this lecture?
Week 6 - Friday.  What did we talk about last time?  Loop examples.
For Friday Read No quiz Program 6 due. Program 6 Any questions?
VG101 RECITATION 5 By TAs. CONTENTS How to read Vg101Class.h Samples about graphics About assignment 5 Array.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Re-Intro to Object Oriented Programming
Intro To Classes Review
Week 14 - Monday CS 121.
Sequences 9/18/ :20 PM C201: Linked List.
Defining Classes and Methods
Inheritance, Polymorphism, and Interfaces. Oh My
Object-Oriented Programming
Week 7 - Monday CS 121.
Day 11 The Last Week!.
Presentation transcript:

Week 11 - Friday

 What did we talk about last time?  Object methods  Accessors  Mutators  Constructors  Defining classes

 An object is the actual data that you can use in your code  A class is a template whereby you can create objects of a certain kind  Class =Car  Object=Mitsubishi Lancer Evolution X  Just like int is a type and 34 is an instance of that type  A key difference is that you can define new classes

 When designing classes, they contain two kinds of elements:  Members  Methods

public class Name {private int member1; private double member2; private Hedgehog member3; public Name() { … } public int method1( double x ) { … } Class definition Member declarations Constructor definition Method definition

 Let’s create a Student class  Each Student will contain  First Name: String  Last Name: String  GPA: double  ID: int  We need a constructor specifying each of these things, accessors to read them later, and mutators to change GPA and ID

 Using the Student class, we can create a roster of students  The roster is just an array of Student objects  We’ll read in some student information from a file and create lots of Student objects  Then, with our array, we can do some operations:  Print out a nicely formatted roster  Find the average GPA of all students  Determine the valedictorian

 We can make a Ball class  Each Ball will have:  Color: Color  x Location: double  y Location: double  Radius: double  x Velocity: double  y Velocity: double  We will need a constructor specifying these values and a method to update the position of the ball over time

 With the Ball class created, it’s easy to make a program that shows balls bouncing all over the screen  We simply create an array of Ball objects and update them repeatedly

 We can extend the idea of moving balls further  Let’s make some balls hunters and some balls prey  Hunters search for the nearest prey  If they reach a particular prey, they eat it  Prey balls always head away from the nearest hunter

 The Prey class has:  x Location: double  y Location: double  Aliveness: boolean  Speed: double  It also has accessors for x, y, and aliveness and a method we can use to kill the prey  Finally, it has an update method where it decides what it will do next

 The Hunter class has:  x Location: double  y Location: double  Speed: double  It also has accessors for x and y  Finally, it also has an update method where it decides what it will do next

 Finish object examples  Class variables and constants  Big Oh notation

 Keep working on Project 4  Due next Friday