Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/http://creativecommons.org/licenses/by-nc-

Slides:



Advertisements
Similar presentations
Methods. int month; int year class Month Defining Classes A class contains data declarations (static and instance variables) and method declarations (behaviors)
Advertisements

1 Lecture Today’s Topics Classes –Attribute (variables) –Behaviors (methods) Using methods –How to write methods –How to use methods Scope –Private.
CSE 113 Week 3 January 28 – February 1, Monday Announcements  Software Installation Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 Bring your laptop or.
CS 106 Introduction to Computer Science I 02 / 28 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
TOPIC 3 INTRODUCTION TO PROGRAMMING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
04-Intro-Object-Oriented-In-Java1 Barb Ericson Georgia Institute of Technology Sept 2009 Introduction to Object-Oriented Programming in Java.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
Introduction to Programming Writing Java Beginning Java Programs.
Lecture 2: Static Methods, if statements, homework uploader.
TOPIC 3 INTRODUCTION TO PROGRAMMING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
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.
Methods in Java CSC1401. Overview In this session, we are going to see how to create class-level methods in Java.
CSE8A Lecture3 TODO: –Finish PSA1 individually (no partner!) and turn it in with the bundlePSA1 command GET AN INTERVIEW for PSA1 from a tutor See tutor.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Georgia Institute of Technology Barb Ericson Georgia Institute of Technology May 2006 Teaching Java using Turtles part 2.
CSE8A Lecture2 Check the class web page (and discussion board, linked form webpage) for news and info: cse8a.weebly.com Lab starts this week. Discussion.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Problem of the Day  Why are manhole covers round?
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Introduction to Computers and Programming Lecture 14: User defined methods (cont) Professor: Evan Korth New York University.
Introduction to programming in the Java programming language.
CS/ENGRD 2110 SPRING 2012 Lecture 2: Objects and classes in Java 1.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
Introduction to Programming Writing Java Beginning Java Programs.
Identifiers Identifiers in Java are composed of a series of letters and digits where the first character must be a letter. –Identifiers should help to.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
CSE8A: Introduction to Programming in Java Fall 2012 Prof. Christine Alvarado cse8afall.weebly.com.
Georgia Institute of Technology Simulations Barb Ericson Jan 2005.
Introduction to Methods Shirley Moore CS 1401 Spring 2013 cs1401spring2013.pbworks.com April 1, 2013.
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
1 Class 1 Lecture Topic Concepts, Definitions and Examples.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
CS/ENGRD 2110 SPRING 2016 Lecture 2: Objects and classes in Java 1.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Functions in C++ Top Down Design with Functions. Top-down Design Big picture first broken down into smaller pieces.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Georgia Institute of Technology Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology North Jeddah Branch King Abdulaziz University.
1 Good Questions Spark discussion Motivate a topic Address a common misconception Help students “speak” in the language of your discipline Foster reflection.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
Problem of the Day  Why are manhole covers round?
Lecture 3: Method Parameters
Content Programming Overview The JVM A brief look at Structure
CSE 8A Lecture 17 Reading for next class: None (interm exam 4)
Creative Commons Attribution Non-Commercial Share Alike License
CSE 143 Lecture 9 References and Linked Nodes reading: 3.3; 16.1
CS/ENGRD 2110 Spring 2017 Lecture 5: Local vars; Inside-out rule; constructors
CSE 8A Lecture 6 Reading for next class:
Teaching Java using Turtles part 3
Creative Commons Attribution Non-Commercial Share Alike License
Lecture 3: Method Parameters
Creative Commons Attribution Non-Commercial Share Alike License
Creative Commons Attribution Non-Commercial Share Alike License
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
More on Creating Classes
Teaching Java using Turtles part 2
Agenda for Unit 3: Functions
Presentation transcript:

Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/ sa/3.0/ Original Developer: Beth Simon, 2009

CSE8A Lecture3 TURN IN INTEGRITY FORMS NOW! (pass to aisle) SIT WITH YOUR DISCUSSION GROUP –Come to the front if you don’t know where they are TODO: –Contact your pair programming partner via or find one on the discussion forum Post the 6 hours you have reserved to work together –Prepare for quiz on Friday –Work on PSA1 WITH YOUR PARTNER! Expect to spend 6 hours! Read next class: pages 60-89, take the online reading quiz. CLICKERS OUT! LAPTOPS?

By the end of today’s class you should be able to… LG4: Be able to track a turtle’s path by reading and tracing code LG5: Identify common errors in Java code and use computing terminology to describe them LG6: Read and modify a method to perform a given task with a Turtle. Specifically understand the use of a parameter to a method. LG7: Know which methods get stored in Turtle.java and which get stored in their own files (and why). LG8: Describe return values of methods and identify ones from methods you have used

Lab and Pair Programming Lab was a blast! What’s it about? –Not just “typing in code” but –ASKING QUESTIONS about what that code is doing and why! –Everyone should ask at least one question in lab every day. What is pair programming? –Driver/Navigator Why pair programming? –People who pair in a first programming course, do BETTER in a second programming course. Note: your pair partner in lab is DIFFERENT (and changes each week) than for homework

What effect do parameters have? (Draw the turtle actions, assuming declared at 25,25 in a world declared with parameters 200, 100) maria.turnLeft(); maria.forward(10); jose.turn(-45); jose.forward(10); raul.turn(90); raul.forward(200); Turtle.turn(405); Turtle.forward(-10); Can you do LG4 now?

Javadocs for the Turtle class (know these) penUp penDown show hide moveTo setName getName

Why is this code incorrect? (pick all that apply – there are no assumptions for this code) A.Nothing is incorrect B.Return type is wrong C.Parameter is used incorrectly D.turnLeft should be turnRight E.use of turtle1 is incorrect public bethsSquare(int size) turtle1.turnLeft(); turtle1.forward(100); turtle1.turnLeft(); turtle1.forward(100); turtle1.turnLeft(); turtle1.forward(100); turtle1.turnLeft(); turtle1.forward(100); 1)SOLO VOTE (20 sec) 2)Discuss in team (1 min) 3)GROUP VOTE (15 sec)

Fix the code (write on the slide crossing out incorrect stuff and adding stuff to make it correct) public void bethsSquare(int size) turtle1.turnLeft(); turtle1.forward(100); turtle1.turnLeft(); turtle1.forward(100); turtle1.turnLeft(); turtle1.forward(100); turtle1.turnLeft(); turtle1.forward(100);

Quick Comparison: Other methods with parameters that you know System.out.println(“This is a parameter of String type); int x = 45; System.out.println(x); //Param of int type turtle1.setName(“George”); turtle2.moveTo(45,115); Now, back to the bethsSquare method… public void bethsSquare(int size)

What’s the right way to “call” that method to draw a square? 1)SOLO VOTE (60 sec) 2)Discuss in team (2 min) 3)GROUP VOTE (15 sec) World w = new World(); Turtle t = new Turtle(10,10, w); t = bethsSquare(50); World w = new World(); Turtle t = new Turtle(10,10, w); t.bethsSquare(); World w = new World(); Turtle t = new Turtle(10,10, w); t.bethssquare(); World w = new World(); Turtle t = new Turtle(10,10, w); t = bethssquare(50); A B C D E None of the above

Storing methods in the correct file We just wrote 2 methods. They each have to be stored in a different place. bethsSquare is a method that can be called on a Turtle so it needs to be in the Turtle class ( Turtle.java ) –t.bethsSquare(50); Then we wrote code to “test out” our Turtle method to “act on” a specific turtle. –That needs to go in a method that we can make up a name for… like SpecialTester.java

So we might in Dr. Java open a new file and put this in it. public class SpecialTester { public static void main(String []args) { World w = new World(); Turtle t = new Turtle(10,10, w); t.bethsSquare(); } And Save As…?

For PSA3: Where are files stored and WHY? 1) drawShape –A method which acts on a turtle object to make it complete a set of steps to make a closed form shape of your choosing 2) createShapes –Directs 4 different turtles in calling the drawShape method to make 4 nested copies of your shape and 2

Writing Methods: Rules and Why Methods are a way of “encapsulating” (putting together in one place/one name) a series of code statements. They are “wrapped” in their –Method header (visibility, return type, name, parameter list) –And { and } enclose all the statements that we want to have done when we “call” that method WHY? –We do this when we have a set of statements that we may want to have done multiple times (and possibly for multiple objects/turtles)

Why Do Methods Get Stored in Turtle.java? If a method describes a “general action” a turtle could reasonably be expected to do –It goes in the Turtle class If it’s a specific “application” that is just a “one off” need –It’s its own program (createShapes, myWackyTurtleProgram, etc) Classes (like Turtle and Picture) are made up of –Data about them –Methods/Actions that can be taken on them

Pictures! DEMO You NEED TO try typing in the code to (for Pictures) –Create –Show –Open –Explore

What types are returned by these method calls? A) main main Picture String B) Turtle Turtle Picture String 1)SOLO VOTE (60 sec) 2)Discuss in team (2 min) 3)GROUP VOTE (30 sec) 1) turtle1.turnLeft(); 2) turtle1.getName(); 3) FileChooser.pickAFile(); 4) new Picture(); B) void void Picture String C) void void String Picture E) None Of The Above

What is a return value?