10/16/07.

Slides:



Advertisements
Similar presentations
2/7/2008. >>> Overview * boolean * while * random * tuples.
Advertisements

BUILDING JAVA PROGRAMS CHAPTER 3 PARAMETERS AND OBJECTS.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3: Parameters, Return, and Interactive Programs Lecture 3-1: Parameters (reading: 3.1)
Week 3 parameters, return, math, graphics Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise.
Week 3 parameters and graphics Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise noted,
Week 3 parameters, return, math, graphics Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise.
Week 2 ______ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 3: Parameters, Return, and Interactive Programs.
Topic 7 parameters Based on slides bu Marty Stepp and Stuart Reges from "We're flooding people with information. We.
Building Java Programs
11/27/07. >>> Overview * objects * class * self * in-object methods * nice printing * privacy * property * static vs. dynamic * inheritance.
CS 112 Introduction to Programming Variable Scoping; Nested Loops; Parameterized Methods Yang (Richard) Yang Computer Science Department Yale University.
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
Week 4. >>> Overview * if else * returns * input.
Week 7 Review and file processing. >>> Methods Hello.java public class Hello { public static void main(String[] args){ hello(); } public static void hello(){
Unit 3 parameters and graphics Special thanks to Roy McElmurry, John Kurkowski, Scott Shawcroft, Ryan Tucker, Paul Beck for their work. Except where otherwise.
1 Building Java Programs Chapter 7: Arrays These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold, or.
CS 112 Introduction to Programming Graphics; Animation Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone:
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
Building Java Programs Parameters and Objects. 2 Redundant recipes Recipe for baking 20 cookies: –Mix the following ingredients in a bowl: 4 cups flour.
Week 3 parameters and graphics Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise noted,
Building Java Programs Chapter 3 Lecture 3-1: Parameters reading: 3.1.
1 Building Java Programs Chapter 3: Introduction to Parameters and Objects These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They.
Week 2 expressions, variables, for loops Special thanks to Scott Shawcroft, Ryan Tucker, Paul Beck, Hélène Martin, Kim Todd, John Kurkowski, and Marty.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 4: Loop Figures and Constants reading:
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
1/10/2008. >>> About Us Paul Beck * Third quarter TA * Computer Engineering * Ryan Tucker * Second quarter TA * Computer.
10/9/07 ______ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||
Copyright 2010 by Pearson Education Building Java Programs Chapter 3 Lecture 3-1: Parameters reading: 3.1.
8/2/07. >>> About Me Scott Shawcroft * Junior * Computer Engineering * Third Quarter TA * Creative Commons Intern * Small-time Open Source Developer
Copyright 2009 by Pearson Education Building Java Programs Chapter 3 Lecture 3-1: Parameters reading: 3.1 self-check: #1-6 exercises: #1-3 videos: Ch.
10/30/07. >>> Overview * boolean * randomness * while * tuples.
11/13/07. >>> Overview * lists/arrays * reading files * writing files.
10/30/07.
10/23/07. >>> Overview * if else * returns * input.
Building Java Programs Chapter 3
10/9/07 ______ < Moo? > \ ^__^ \ (oo)\_______ (__)\ )\/\
Building Java Programs
Exercise Java programming
Building Java Programs
Building Java Programs
Building Java Programs
parameters, return, math, graphics
Building Java Programs
1/22/2008.
CSc 110, Autumn 2017 Lecture 9: Graphics and Nested Loops
Topic 7 parameters "We're flooding people with information. We need to feed it through a processor. A human must turn information into intelligence or.
expressions, variables, for loops
Building Java Programs
expressions, variables, for loops
Redundant recipes Recipe for baking 20 cookies:
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
CSE 142 Lecture Notes Graphics with DrawingPanel Chapter 3
Building Java Programs
Building Java Programs
Building Java Programs
CSE 142 Lecture Notes Global Constants, Parameters, Return Values
Building Java Programs
CSE 142 Lecture Notes Defining New Types of Objects, cont'd.
Scope scope: The part of a program where a variable exists. From its declaration to the end of the { } braces A variable declared in a for loop exists.
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Lecture 8-2: Object Behavior (Methods) and Constructors
Building Java Programs
Presentation transcript:

10/16/07

>>> Overview * parameters * returns * graphics

>>> Parameters Parameters are easy in Python once you know Java's. Simply remove all types from the method header and do the normal conversion. def print_sum(x,y): print str(x+y) sum(2,3) print_sum.py 1 2 3 4 public static void printSum(int x, int y) { System.out.println(x+y); } PrintSum.java 1 2 3 4

>>> Defaults Unlike Java, Python's parameters can have default values to use when one is not given. def print_range(start=1,end=1,interval=1,sep=" "): for i in range(start,end,interval): print i + sep print end print range(0,7) print_range(1,7,1,", ") print_range.py 1 2 3 4 5 6 7

>>> Keywords When calling a function with a number of parameters with defaults you can modify particular parameters with a keyword so that you do not need to specify all preceding parameters. def print_range(start=1,end=1,interval=1,sep=" "): for i in range(start,end,interval): print i + sep print end print range(0,7) print_range(1,7,1,", ") print_range(end=7,sep=", ") print_range.py 1 2 3 4 5 6 7 8 9

>>> Star box scott @ yossarian ~ $ python stars.py ********** // CSE 142 Autumn 2007, Marty Stepp // // This program prints many lines and boxes of stars in a loop. // This version uses for loops and also shows an advanced concept: // The String data type. (hasn't been covered in lecture yet) public class StarsWithLoops { public static void main(String[] args) { // the original program's output (lines and boxes of stars) drawLineOfStars(13); drawLineOfStars(7); drawLineOfStars(35); drawBox(5, 4); drawBox(10, 6); System.out.println(); // additional output: 3x6, 4x8, 5x10, ..., 10x20 boxes for (int i = 3; i <= 10; i++) { drawBox(2 * i, i); } // Prints the given character the given number of times. // String is the data type for text characters and messages in Java. public static void printCharacter(String character, int times) { for (int i = 1; i <= times; i++) { System.out.print(character); // Draws a line of stars with the given length. public static void drawLineOfStars(int stars) { for (int i = 1; i <= stars; i++) { System.out.print("*"); // Draws a box of stars with the given dimensions. public static void drawBox(int width, int height) { // top drawLineOfStars(width); // middle for (int line = 1; line <= height - 2; line++) { printCharacter(" ", width - 2); System.out.println("*"); // bottom ********** * *

>>> Graphics Graphics work similar than in Java. The methods are different though. from drawingpanel import * panel = DrawingPanel(500,500) g = panel.getGraphics() #draw stuff here g.create_oval(200,200,300,300,fill="pink",width=0) panel.mainloop() pink.py 1 2 3 4 5 6 7 8 9 g.create_line(x0,y0...xN,yN,...) g.create_oval(x0,y0,x1,y1,...) g.create_polygon(x0,y0...xN,yN,...) g.create_rectangle(x0,y0,x1,y1,...) g["bg"]=<color>

>>> A better car...

© 2007 Scott Shawcroft, Some Rights Reserved Except where otherwise noted, this work is licensed under http://creativecommons.org/licenses/by-nc-sa/3.0 Python® and the Python logo are either a registered trademark or trademark of the Python Software Foundation. Java™ is a trademark or registered trademark of Sun Microsystems, Inc. in the United States and other countries.