Computation as an Expressive Medium Lab 3: (Methods and) Classes Jason Alderman.

Slides:



Advertisements
Similar presentations
Creative Computing. Comments on Assignments Everyone did very well Report writing needs more work Jumping scale Update first then draw.
Advertisements

ArrayLists The lazy mans array. Whats the matter here? int[] list = new int[10]; list[0] = 5; list[2] = hey; list[3] = 15; list[4] = 23;
Objects. 2 Object Oriented Programming (OOP) OOP is a different way to view programming Models the real world A different view than Structured programming.
CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
Written by: Dr. JJ Shepherd
IAT 334 Lab 2 Computer Graphics: Rocket, PImage. June 4, 2010IAT 3342 Outline  Programming concepts –Programming Computer Graphics –Transformations –Methods.
IAT 800 Foundations of Computational Art and Design Lecture 2.
Sep 26, Fall 2006IAT 800 Lecture 6 Methods and Classes.
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
IAT 800 Lecture 4. Sept 18, Fall 2006IAT 8002 Outline  Programming concepts –Methods –Classes  Talk about project 1  Reading: Read Chapters 1-4 of.
School of Computing Science CMT1000 © Ed Currie Middlesex University Lecture 10: 1 TEST!!
CS 106 Introduction to Computer Science I 02 / 27 / 2008 Instructor: Michael Eckmann.
Chapter 3 Using Classes and Objects. 2 Creating Objects  A variable holds either a primitive type or a reference to an object  A class name can be used.
CS 201 Functions Debzani Deb.
IAT 800 Lecture Oct, Fall 2006IAT 8002 Outline  Programming concepts –Super and this –Java SDK classes Lists Reading the Java docs –Programming.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
IAT 355 Lecture 4 Computer Graphics: Rocket. May 9, 2014IAT 3552 Outline  Programming concepts –Programming Computer Graphics –Transformations –Methods.
Week 10 - Monday.  What did we talk about last time?  Method overloading  Lab 9.
Classes / Objects An introduction to object-oriented programming.
Variables, Functions & Parameter Passing CSci 588 Fall 2013 All material not from online sources copyright © Travis Desell, 2011.
COSC 1P02 Introduction to Computer Science 3.1 Cosc 1P02 Week 3 Lecture slides Birthdays are good for you. Statistics show that the people who have the.
CSE 131 Computer Science 1 Module 1: (basics of Java)
Loops and Iteration for Statements, while Statements and do-while Statements.
More arrays Primitive vs. reference parameters. Arrays as parameters to functions.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
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.
Week 14 - Monday.  What did we talk about last time?  Introduction to C++  Input and output  Functions  Overloadable  Default parameters  Pass.
CS107 References and Arrays By Chris Pable Spring 2009.
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004 Assignment 6.
CMSC 150 CLASSES CS 150: Mon 6 Feb 2012 Images: Library of Congress.
Objects. The Heart of the Matter - The "Black Box" Object-oriented software is all about objects. An object is a "black box" which receives and sends.
February ,  2/16: Exam 1 Makeup Papers Available  2/20: Exam 2 Review Sheet Available in Lecture  2/27: Lab 2 due by 11:59:59pm  3/2:
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Elementary C++. Procedural Programming Split your problem into simpler parts then solve each part separately Recognize common parts and solve them only.
Working With Objects Tonga Institute of Higher Education.
LCC 6310 Computation as an Expressive Medium Lecture 8.
LCC 6310 Computation as an Expressive Medium Lecture 2.
LCC 6310 Computation as an Expressive Medium Lecture 6.
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004 Functional Abstraction Reduces Complexity.
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
Written by: Dr. JJ Shepherd
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
Fact Family Fun Do you know what a fact family is? A fact family is a bunch of numbers that all work together…
Fact Family Fun Do you know what a fact family is? A fact family is a bunch of numbers that all work together…
IAT 265 Lecture 7 Objects and ArrayList. May 19, 2016IAT 2652 Outline  Programming concepts –Super and this –Java SDK classes Lists Reading the Java.
Objects as a programming concept
Content Programming Overview The JVM A brief look at Structure
Introduction to Computer Science / Procedural – 67130
Computation as an Expressive Medium
LCC 6310 Computation as an Expressive Medium
Programs – Dynamic Linking and Loading
Lecture 11 B Methods and Data Passing
Computation as an Expressive Medium
CSC 253 Lecture 8.
Lesson 2: Building Blocks of Programming
CSC 253 Lecture 8.
Functions Pass By Value Pass by Reference
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
February , 2009 CSE 113 B.
Java Programming Language
Lecture 6 Methods and Classes
IAT 800 Foundations of Computational Art and Design
LCC 6310 Computation as an Expressive Medium
CS 1054: Lecture 2, Chapter 1 Objects and Classes.
LCC 6310 Computation as an Expressive Medium
References Revisted (Ch 5)
Lecture 6 Methods, Classes, Inheritance
Methods and Data Passing
Presentation transcript:

Computation as an Expressive Medium Lab 3: (Methods and) Classes Jason Alderman

ARE YOU READY TO RUMMMMMMBBLLLLLLE?! A few good programming practices A few good programming practices Methods: Oi, what’s the deal, eh? Methods: Oi, what’s the deal, eh? Classes: Here’s where it gets really fun… Classes: Here’s where it gets really fun…

Drive friendly. Code friendly. Comments are your friend! Comments are your friend! Put a block of commenting at the top of each program that explains what it does Put a block of commenting at the top of each program that explains what it does Comment in code what a section will do Comment in code what a section will do Comment when you appropriate code!! Comment when you appropriate code!! Auto-format is also your friend!! Auto-format is also your friend!! Your programs will have at least three sections Your programs will have at least three sections Variable declaration Variable declaration setup() setup() draw() draw() Also known as: gank, borrow, reuse, yoinks, etc. Give due credit!

Methods. Reloaded. Methods, also known as Methods, also known as Functions (methods which return something) Functions (methods which return something) Procedures (methods which don’t return stuff) Procedures (methods which don’t return stuff) Method declaration Method declaration Method call Method call void vendingMachine( int coinCents ){ println("You inserted "+coinCents+" cents."); } int quarter = 25; vendingMachine(quarter);

Methods. Reloaded. Method declaration Method declaration The method declaration is like a blueprint The method declaration is like a blueprint Doesn't matter if declaration is before or after call! Doesn't matter if declaration is before or after call! Parameter name (e.g. coinCents) is just the name given to data passed into the method… Parameter name (e.g. coinCents) is just the name given to data passed into the method… void vendingMachine( int coinCents ){ println("You inserted "+coinCents+" cents."); } void means doesn't return anything parameter

Methods. Reloaded. Method call Method call vendingMachine(quarter) == vendingMachine(25) vendingMachine(quarter) == vendingMachine(25) Method call must occur in either setup(), draw(), or another method… Method call must occur in either setup(), draw(), or another method… You can call it as many times as you like! You can call it as many times as you like! vendingMachine()s for everyone!! Hooray! vendingMachine()s for everyone!! Hooray! int quarter = 25; vendingMachine(quarter); argument

Avast, Cap'n! Java Ahoy! Classes: They’re not just for breakfast, anymore. Classes: They’re not just for breakfast, anymore. Remember that slide a couple labs ago? Remember that slide a couple labs ago? Types Types Primitives: int, float, char, boolean … Primitives: int, float, char, boolean … Objects: array, string, class … Objects: array, string, class … This bit of information is courtesy your memory of things learned. Don't leave home without it.

Objects We’ve worked with some objects before, like Arrays. We’ve worked with some objects before, like Arrays. We can make our own objects, to keep related data together, and methods to control that data. We can make our own objects, to keep related data together, and methods to control that data.

Classes Classes are the blueprints for our new objects. Classes are the blueprints for our new objects. To declare a new Class (a new type of object): To declare a new Class (a new type of object): class MyToy { // fields (class variables) // methods (class functions) } Hey! You reused that metaphor!

Fields and Methods class MySquare { int xPos, yPos; MySquare(x, y) { xPos = x; yPos = y; } void drawMe() { rect(xPos, yPos, 50, 50); } xy drawMe() fields constructor methods (one kind of method)

Fields and Methods class MySquare { int xPos, yPos; MySquare(x, y) { xPos = x; yPos = y; } void drawMe() { rect(xPos, yPos, 50, 50); } xy drawMe() MySquare square1 = new MySquare(10, 10); MySquare square2 = new MySquare(20, 90); 10 drawMe() 2090 drawMe() square1square2

Fields and Methods class MySquare { int xPos, yPos; MySquare(int x, int y) { xPos = x; yPos = y; } void drawMe() { rect(xPos, yPos, 50, 50); } MySquare square1 = new MySquare(10, 10); MySquare square2 = new MySquare(20, 90); xy drawMe() 10 drawMe() 2090 drawMe() square1 square2 square1.drawMe(); square2.drawMe();

Arrays of Objects? Sure! Let’s make a bunch of squares! Sure! Let’s make a bunch of squares! MySquare[] squares = new MySquare[10]; // initialize all of our squares. for (int i = 0; i < 10; i ++) { squares[i] = new MySquare(i*10, i*10); } squares[4].drawMe(); // draw the 4 th square.

Asteroids Let’s adapt this to make an array of Asteroids for our rocket from lecture. Let’s adapt this to make an array of Asteroids for our rocket from lecture. class Asteroid { //fields float rotation = 0; float xPos, yPos; float velocityX, velocityY; long lastDrawMillis = 0; … } …except you didn't finish going over the Asteroids code in class, did you? Just follow along and we'll go over the code in a second (not on slides).

Asteroids When we create an asteroid, let’s have it start in a random position, and move in a random direction. When we create an asteroid, let’s have it start in a random position, and move in a random direction. Class Asteroid { … // constructor Asteroid() { xPos = random(0, 400); yPos = random(0, 400); rotation = random(0, TWO_PI); velocityX = sin(rotation)*10; velocityY = -cos(rotation)*10; }

Asteroids Class Asteroid { … // draw method void drawMe() {

OOP, we'll do it again. Programming practices Programming practices Methods, redux Methods, redux Classes, hoo-boy! Classes, hoo-boy! clone-o-matic The more the merrier! MUHAHAHA!