CSE 113 Introduction to Computer Programming Lecture slides for Week 5 Monday, September 26 th, 2011 Instructor: Scott Settembre.

Slides:



Advertisements
Similar presentations
2.1 Program Construction In Java
Advertisements

CSE 113 Introduction to Computer Programming Lecture slides for Week 3 Monday, September 12 th, 2011 Instructor: Scott Settembre.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
CSE 113 Introduction to Computer Programming Lecture slides for Week 10 Monday, October 31 th, 2011 Instructor: Scott Settembre.
CSE 113 Introduction to Computer Programming Lecture slides for Week 6 Monday, October 3 rd, 2011 Instructor: Scott Settembre.
Defining classes and methods Recitation – 09/(25,26)/2008 CS 180 Department of Computer Science, Purdue University.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
Chapter 41 Defining Classes and Methods Chapter 4.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Loops – While, Do, For Repetition Statements Introduction to Arrays
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Today’s quiz on 8.2 B Graphing Worksheet 2 will be given at the end of class. You will have 12 minutes to complete this quiz, which will consist of one.
Admin Office hours 2:45-3:15 today due to department meeting if you change addresses during the semester, please unsubscribe the old one from the.
Please open your laptops, log in to the MyMathLab course web site, and open Daily Quiz 18. You will have 10 minutes for today’s quiz. The second problem.
Please open your laptops and pull up Quiz Only the provided online calculator may be used on this quiz. You may use your yellow formula sheet for.
Games and Simulations O-O Programming in Java The Walker School
Chapter 9 Interactive Multimedia Authoring with Flash - Introduction to Programming “Computers and Creativity” Richard D. Webster, COSC 109 Instructor.
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
Please open Daily Quiz 34. A scientific calculator may be used on this quiz. You can keep your yellow formula sheets out when you take the quiz. Remember.
CSE 113 Introduction to Computer Programming Lecture slides for Week 4 Monday, September 19 th, 2011 Instructor: Scott Settembre.
Instructor: Craig Duckett Assignment 1 Due Lecture 5 by MIDNIGHT – NEXT – NEXT Tuesday, October 13 th I will double dog try to.
1 CSC 201: Computer Programming I B. S. Afolabi. Introduction  3 unit course  2 hours of lecture/week Thursdays 4.00pm – 6.00pm Mondays 4.00pm – 6.00pm.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
CSE 113 Introduction to Computer Programming Lecture slides for Week 2 Wednesday, September 7 th, 2011 Instructor: Scott Settembre.
Variables and Arithmetic. From last class More drawing functions: strokeWeight(n); // higher the n value broader the stroke fill(k) ; // single parameter.
Semester Review. As we have discussed, Friday we will have in class time for you to work on a program, this program will come with instructions and you.
PHP Logic. Review: Variables Variables: a symbol or name that stands for a value – Data types ( Similar to C++ or Java): Int, Float, Boolean, String,
CSE 113 Introduction to Computer Programming Lecture slides for Week 1 Monday, August 29 th, 2011 Instructor: Scott Settembre.
CSE 113 Introduction to Computer Programming Lecture slides for Week 7 Monday, October 10 th, 2011 Instructor: Scott Settembre.
CPSC 121: Models of Computation Unit 0 Introduction George Tsiknis Based on slides by Patrice Belleville and Steve Wolfman.
CSE 113 Introduction to Computer Programming Lecture slides for Week 12 Monday, November 14 th, 2011 Instructor: Scott Settembre.
1 CSE1301 Computer Programming: Revision. 2 Topics Type of questions What do you need to know? About the exam Exam technique Staff consultation Revision.
Agenda Object Oriented Programming Reading: Chapter 14.
CSC 107 – Programming For Science. The Week’s Goal.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Applications Development
CSC 221: Computer Programming I Fall 2001 course overview  what did we set out to learn?  what did you actually learn?  where do you go from here? 
1 CS1100 Fall Instructor: David Gries CS100M: Matlab No prior programming experience One semester of calculus Math & engineering type problems CS100J:
Please CLOSE YOUR LAPTOPS, and turn off and put away your cell phones, and get out your note- taking materials.
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:
1 CSC 221: Computer Programming I Spring 2008 course overview  What did we set out to learn?  What did you actually learn?  Where do you go from here?
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Chapter 3 Object Interaction.  To construct interesting applications it is not enough to build individual objects  Objects must be combined so they.
Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013.
Introduction to Computers and Programming Lecture 7:
Math 010 online work that was due today at the start of class: Section 1.3A Online Homework.
Week 12 - Monday.  What did we talk about last time?  Defining classes  Class practice  Lab 11.
Expressions and Order of Operations Operators – There are the standard operators: add, subtract, divide, multiply – Note that * means multiply? (No times.
CSE 1340 Introduction to Computing Concepts Class 1 ~ Intro.
CS 367 Introduction to Data Structures Charles N. Fischer Fall s367.html.
CISC105 – General Computer Science Class 4 – 06/14/2006.
CS122 Engineering Computation Lab Lab 2 Bruce Char Department of Computer Science Drexel University Winter 2012.
1 CS100J Spring Instructor: David Gries CS100M: Matlab No prior programming experience One semester of calculus Math & engineering type problems.
PROBLEM SOLVING AND PROGRAMMING ISMAIL ABUMUHFOUZ | CS 170.
Any questions on the Section 5.4 homework?. Please CLOSE YOUR LAPTOPS, and turn off and put away your cell phones, and get out your note- taking materials.
CS 1428 Final Exam Review. Exam Format 200 Total Points – 60 Points Writing Programs – 45 Points Tracing Algorithms and determining results – 20 Points.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana Pronounced Bah-bah Co-fee Way-ou-see-jah-nah Call him “Baba” or “Dr. Weusijana”
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Eastside Robotics Alliance / Newport Robotics Group 1 T/Th, 6:30 – 8:30 PM Big Picture School Day 3 · 10/9/2014.
Midterm Exam Preperation
Unit 3 Test: Friday.
CS139 October 11, 2004.
Module 4 Loops and Repetition 2/1/2019 CSE 1321 Module 4.
February , 2009 CSE 113 B.
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

CSE 113 Introduction to Computer Programming Lecture slides for Week 5 Monday, September 26 th, 2011 Instructor: Scott Settembre

COURSE ADMINISTRATION Section 1 Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 2

For Project Assistance You can find the up-to-date hours and locations in the “Contact” section of UBLearns. Here are the names, s, and office hours as of 9/26/2011: (Also come to additional labs if you need help) Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 3 Name addressOffice hours Bich (pronounced “Bic”) (11-11:50am) Bell 329 F (12-12:50pm) Bell 329 Troy (3-5pm) Bell 329 Scott (10-11am) Bell 229 F (10-11am) Bell 340 Also at all times by AND video conference by appointment.

You are behind the class if… If you have not completed chapter 1-3 and plan to finish chapter 4 before your lab, then you are behind the rest of the class. Please do the following: – Complete chapter 1-4 in Bell 101. – If you cannot finish up chapter 4 by your lab, then: Finish chapters 1-3, AND THEN Stay up late at night and finish chapter 4 before your lab. You can DO it! Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 4

Lecture and Lab this Week Lectures will go over the following: – Lab Quizzes for Week 3 and 4 – Chapter 5 concepts and more formal definitions mathematical and boolean expressions code abstraction loops local variables arrays (or lists of objects) strings (and string manipulation) icons, jpg, gif, png file differences (not in book yet) Lab will have you do the following: – Finish completely chapters 1-4 if you haven’t – Start on chapter 5, finish what you can’t before the next lab – Working on your Project 1 Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 5

QUIZ ANSWER AND DISCUSSION Section 2 Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 6

Quiz Week 3 and 4 Review I will be going over the answers to the Lab Quizzes from week 3 and 4. I will answer any questions about the quizzes you have. Each quiz is worth 2% of final grade (the quizzes may have a curve applied if appropriate) Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 7

MIDTERM AND FINAL EXAM DISCUSSION Section 3 Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 8

Midterm exam (15%) The midterm exam will be held in lecture on October 21 st. It will cover chapters 1-6, including the exercises in the chapter that you do in lab. It will be a series of true/false, multiple choice, and code examination (running the code in your head), similar to the quizzes that you will have taken. Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 9

Final Exam (25%) The final exam will be during class during the last week of class. It may span two days (I may give half on one day and half the next day). It will consist of questions like the quizzes, as well as some code reading and understanding. More on this in November. Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 10

CHAPTER 5 Section 3 Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 11

Mathematical and Boolean expressions You will find the need to add, subtract, multiply, divide, do modulus (find the remainder after a division) in arithmetic expressions. You will find the need to use the logical operators: AND, OR, and NOT, in boolean expressions. Parenthesis are used just like in real math, to ensure precedence. Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 12

Math Expressions These are sometimes called “arithmetic expressions” and they use the arithmetic operators: Thursday, June 16th, 2011 University at Buffalo: EAS 230 Instructor: Scott Settembre 13 Operator ActionExample +additiona = 1 + 1; // a == 2 -subtractionb = 2 - 1; // b == 1 *multiplicationc = 4 * 4; // c == 16 /divisiond = 5 / 2; // if d is type int, then d == 2 %modulo†e = 5 / 2; // e == 1 † Modulo, sometimes referred to as “mod”, returns the remainder from an integer division.

Code example : using math private int Sum = 0; private int Average = 0; Sum = ; Average = Sum / 6; // or we could have done Average = ( ) / 6; Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 14

Parenthesis, “and”, “or”, “not” Boolean expressions can also include parenthesis for precedence (just like math) and the “AND”, “OR”, or “NOT” logical operators: – “AND” is “&&” – “OR” is “||” – “NOT” is “!” For example: – ( a == 10 && b == 10 )// true if a and b == 10 – ( c 10 )// true if c != 10 – ( d 10 )// always false – ( !(a < b) )// false, if a is less than b Tuesday, June 11th, 2011 University at Buffalo: EAS 230 Instructor: Scott Settembre 15

Code example : using “&&” (and) private int a = 5; private int b = 10; private int c = 20; if ( (a < b) && (b < c) ) { // then a is less than c } else { // then a is not less than c } Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 16

Abstraction Talked about abstraction in class – Examine what it means to abstract a class – Show how to use the constructor to make an abstract class to create a specific object Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 17

More on Wednesday Keep working on your projects. Finish up to and including chapter 4 by your lab section. I will talk more about chapter 5. Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 18

What is “abstraction” for programs? Abstraction is a technique used to make code more general. – It makes code general, so that you do not need to change a class to create something specific. – You will use an abstract class to instantiate a specific object. We have done this before, by shift+left-clicking a class onto the world, but we did not specify how each object was specific. Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 19

Abstract example Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 20 “Dog” class These are all instances of “Dog”, but they are all the same! They all use the same code. They have the same values in their instance variables. They all were created using the code “new Dog()” new Dog()

Abstract example : continued Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 21 “Dog” class What if we made a Dog constructor that took a parameter list? – This way, we can specify some information when we create a new object. – Then if we created a new dog, we can specify its name. new Dog(“Rex”)new Dog(“Woofy”)new Dog(“Fido”)

What does this look like in code? public class Dog extends Actor { private String name; public Dog(String newName) { name = newName; } } Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 22

Another abstraction example Let say we want to make an OceanWorld that has many different types of fish. – However, we only want to make one java class that covers all fish. – We do this because we don’t want to make hundreds of different classes to cover all the different types of fish there are. – All fish swim, and we wouldn’t want to have to write hundreds of different “swim” methods! Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 23

OceanWorld Fish class Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 24 public class Fish extends Actor { public String color = “blue”; public int length = 10; public int speed = 2; public Fish() { // Any initializing code – like loading in a picture file } public void Swim() { move(speed); } }

So to create fish… In the OceanWorld constructor, we would see a lot of: addObject ( new Fish(), 100, 200 ); addObject ( new Fish(), 520, 150 ); addObject ( new Fish(), 302, 63 ); addObject ( new Fish(), 10, 250 ); And they would all have length == 10, speed == 2, and color == “blue”. How boring… Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 25

OceanWorld Fish class using Abstraction Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 26 public class Fish extends Actor { public String color; public int length; public int speed; public Fish(String theColor, int theLength, int theSpeed) { color = theColor; length = theLength; speed = theSpeed; // Any other initializing code – like loading in a picture file } public void Swim() { move(speed); // note: This is “speed” from the instance variable, not “theSpeed” } }

So to create fish with abstraction… In the OceanWorld constructor, we would see a lot of: addObject ( new Fish(“red”,6,2), 100, 200 ); addObject ( new Fish(“blue”,8,5), 520, 150 ); addObject ( new Fish(“white”,1,1), 302, 63 ); addObject ( new Fish(“blue”,8,7), 10, 250 ); And they would all have different lengths, colors, or speeds, proving that there really are many fish in the sea! Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 27

Control code : Loops Besides the if..else statement, loops are the other control code you will need to learn. It allows you to communicate to the computer that it should run a block of code over and over again, until some condition is met. Beware! You can make a mistake and have a loop run FOREVER! – This is called an infinite loop and will lock up your machine. – Greenfoot handles this (so your machine will not really lock up), but other languages (and running your program directly on Java on another machine) may lock it up. Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 28

What is the “while” loop. The “while” loop is one form of loop you will get good at. Here is what it looks like: while ( some-condition-is-true ) { Do statement #1 Do statement #2 Do statement #3 … Do statement #n } Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 29 Then loop back and check the condition again to see if we need to run the code block again.

“while” loop example #1 int x = 0; while ( x < 5 ) { x = x + 1; } // what is the value of x after the loop??? // x == 5 Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 30

“while” loop example #2 int x = 0; while ( x == 5 ) { x = x + 1; } // what is the value of x after the loop??? // x == 0 Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 31

“while” loop example #3 int x = 0; while ( x < 5 ) { x = x + 2; } // what is the value of x after the loop??? // x == 6 Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 32

“while” loop example #4 int x = 0; while ( x <= 5 ) { x = x + 1; } // what is the value of x after the loop??? // x == 6 Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 33

What is a “local variable”? A local variable is a variable that stores data, however, this data (and the variable) goes away after the code block it is in is not being used. It also does not need to use the keywords “public” or “private”. You can easily set its value with the assignment operator “=“ when you declare it. Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 34

Example of a local variable public void Swim() { if ( !sleeping ) { int counter = 0; // “counter” is the local variable while (counter < speed) { move();// move the fish one grid space counter = counter + 1;// increment the counter } //  What is the value of “counter” here? } //  What is the value of “counter” here? *trick question* } Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 35

Which are local variables and which are instance variables? public class A extends Z { public int myVar1; private int myVar2; public A() { int myVar3 = 100; } public void B( int myVar4) { int myVar5; } } Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 36 Instance Variables Local Variables It is a parameter, but it is also a local variable

More on Monday Keep working on your projects. Finish up chapters 1-4, and most of chapter 5. Arrays next! Monday, Sept. 26th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 37