CSE 113 Introduction to Computer Programming Lecture slides for Week 6 Monday, October 3 rd, 2011 Instructor: Scott Settembre.

Slides:



Advertisements
Similar presentations
CSE 113 Introduction to Computer Programming Lecture slides for Week 3 Monday, September 12 th, 2011 Instructor: Scott Settembre.
Advertisements

How to study for A&P Adapted from “get ready for A&P” By Lori K. Garrett.
Intro to CIT 594
John Hurley Cal State LA
What’s this course all about?
No calculators or notes can be used on this quiz.
Zhang Hongyi CSCI2100B Data Structures Tutorial 2
CSE 113 Introduction to Computer Programming Lecture slides for Week 10 Monday, October 31 th, 2011 Instructor: Scott Settembre.
What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
Instructor Dr. Ken Rodham –3370 TMCB – –Office Hours: By Appointment.
OBJECT ORIENTED PROGRAMMING I LECTURE 1 GEORGE KOUTSOGIANNAKIS
CSC 171 – FALL 2004 COMPUTER PROGRAMMING LECTURE 0 ADMINISTRATION.
Dr. Tatiana Erukhimova [year] Overview of Today’s Class Folders Syllabus and Course requirements Tricks to survive Mechanics Review and Coulomb’s Law.
Math 010 online work that was due today at the start of class:
Next class session: Test 1 on all sections covered from Chapters 1 and 2 Remember: If you haven’t yet passed the Gateway Quiz, you need to review your.
Computer Science 102 Data Structures and Algorithms V Fall 2009 Lecture 1: administrative details Professor: Evan Korth New York University 1.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 1 1.
CHEMISTRY 10123/10125 Spring 2007 Instructor: Professor Tracy Hanna Phone: Office: SWR 418
Welcome to CS 115! Introduction to Programming. Class URL Please write this down!
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.
COMP Introduction to Programming Yi Hong May 13, 2015.
Lecture 1 Page 1 CS 111 Summer 2015 Introduction CS 111 Operating System Principles.
MGS 351 Introduction to Management Information Systems
--Laurie Wern Overmann August 25, “Students learn math by doing math not by watching someone else do math” Students listen to the instructor while.
CSE 113 Introduction to Computer Programming Lecture slides for Week 2 Wednesday, September 7 th, 2011 Instructor: Scott Settembre.
Leena Razzaq Office: 310BWVH Office hours: Monday 11am-1pm or by appointment jys.
CSE 113 Introduction to Computer Programming Lecture slides for Week 5 Monday, September 26 th, 2011 Instructor: Scott Settembre.
Welcome to CS 115! Introduction to Programming. Class URL Write this down!
1 Principles of Computer Science I Note Set 1 CSE 1341.
CSE 1340 Introduction to Computing Concepts Class 1 ~ Intro.
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.
Lecture 1 Page 1 CS 111 Summer 2013 Introduction CS 111 Operating System Principles Peter Reiher.
Principles of Computer Science I Honors Section Note Set 1 CSE 1341 – H 1.
CSE 113 Introduction to Computer Programming Lecture slides for Week 12 Monday, November 14 th, 2011 Instructor: Scott Settembre.
CPS120: Introduction to Computer Science Winter 2002 Instructor: Paul J. Millis.
CSC1401 Classes - 1. Learning Goals Computing concepts Identifying objects and classes Declaring a class Declaring fields Default field values.
INTRODUCTION TO PROGRAMMING ISMAIL ABUMUHFOUZ | CS 146.
Please CLOSE YOUR LAPTOPS, and turn off and put away your cell phones, and get out your note- taking materials.
Homework due Test the random number generator Create a 1D array of n ints Fill the array with random numbers between 0 and 100 Compute and report the average.
MGS 351 Introduction to Management Information Systems Lecture #1.
REMINDER: If you haven’t yet passed the Gateway Quiz, make sure you take it this week! (You can find more practice quizzes online in the Gateway Info menu.
James Tam Introduction To CPSC 233 James Tam Java Object-Orientation Event driven software.
Math 010 online work that was due today at the start of class: Section 1.3A Online Homework.
James Tam Introduction To CPSC 233 James Tam Java Object-Orientation Graphical-user interfaces.
Data Structures and Algorithms in Java AlaaEddin 2012.
CSE 1340 Introduction to Computing Concepts Class 1 ~ Intro.
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.
REMINDER: If you haven’t yet passed the Gateway Quiz, make sure you take it this week! (You can find more practice quizzes online in the Gateway Info menu.
WELCOME TO MICRO ECONOMICS AB 224 Discussion of Syllabus and Expectations in the Class.
WELCOME TO MANAGERIAL ECONOMICS MT 445 Discussion of Syllabus and Expectations in the Class.
Spring 2008 Mark Fontenot CSE 1341 – Honors Principles of Computer Science I Note Set 1 1.
Computer Science I ISMAIL ABUMUHFOUZ | CS 180. CS 180 Description BRIEF SUMMARY: This course covers a study of the algorithmic approach and the object.
CMSC201 Computer Science I for Majors Lecture 12 – Midterm Review Prof. Katherine Gibson.
CMSC201 Computer Science I for Majors Lecture 13 – Midterm Review
CMSC201 Computer Science I for Majors Lecture 13 – Midterm Review
September 27 – Course introductions; Adts; Stacks and Queues
CMSC201 Computer Science I for Majors Lecture 27 – Final Exam Review
Welcome to CS 1010! Algorithmic Problem Solving.
Welcome to CS 1010! Algorithmic Problem Solving.
GTECH 709 Criteria for evaluation
Welcome to CS 1301! Principles of Programming I.
CMSC201 Computer Science I for Majors Lecture 25 – Final Exam Review
Accelerated Introduction to Computer Science
Midterm Review October 23, 2006 ComS 207: Programming I (in Java)
CMSC201 Computer Science I for Majors Lecture 12 – Midterm Review
Presentation transcript:

CSE 113 Introduction to Computer Programming Lecture slides for Week 6 Monday, October 3 rd, 2011 Instructor: Scott Settembre

COURSE ADMINISTRATION Section 1 Monday, Oct. 3rd, 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, Oct. 3rd, 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 232 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-4, then you are behind the rest of the class. Please do the following: – Complete chapter 1-4 in Bell 101. – Chapter 5 must be finished by the end of this week. Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 4

Lecture and Lab this Week Lectures will go over the following: – Lab Quiz for Week 5 – Chapter 5 concepts and more formal definitions arrays (or lists of objects) strings (and string manipulation) icons, jpg, gif, png file differences (not in book yet) – Starting chapter 6. 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 week – Work on your Project 1 Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 5

QUIZ ANSWER AND DISCUSSION Section 2 Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 6

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

MIDTERM AND FINAL EXAM DISCUSSION Section 3 Monday, Oct. 3rd, 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, Oct. 3rd, 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, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 10

CHAPTER 5 Section 3 Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 11

What is an “array”? “An array is an object that holds multiple variables. These can be accessed using an index.” What is an array??? – It is just a numbered list. What is an index then??? – It is the number that refers to an item on the list. Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 12

array Example int [] grades; grades = { 80, 50, 100 }; // the index starts at 0, so… // grades[0] == 80 // grades[1] == 50 Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 13

array Example 2 private String[] TA = { “Bich”, “Troy” }; // If it was then asked, who is TA[1]? // You then should answer… // “Troy” Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 14

array Example 3 Cars[] obstacles; obstacles[0] = new Car(); obstacles[1] = new Car(); // But what is the computer really doing? Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 15

Behind the “array” In general, the arrays you will be using will be arrays of objects. Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre String[] friends = { “Scott”, “Bich”, “Troy”, “Carmen”} Computer memory friends array “Scott” “Troy” “Bich” “Carmen” [friends array] ???

Things to know about arrays Arrays start with index 0. Each item in the array can also be called an element. Each item/element points to an object. Getting rid of (or clearing) an array does not necessarily get rid of the elements. The objects in the array may still exist. Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 17

array Example 4 int [] grades = { 100, 80, 100, 50 }; int x; x = grades[1] + grades[2] + grades[3]; // What is the value of “x” // If you answered, x == 280, then you forgot that // grades[0] == 100!!! // An index of an array starts at 0! Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 18

array Example 5 int [] ages = {18, 20, 22, 20, 20} int sum = 0; int average; int index = 0; while (index <= 4) { sum = sum + ages[index]; index = index + 1; } average = sum / 5; Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 19 Note: The size of the array is 5 elements, but the last index is 4.

array Example 6 // What is the final result of “sum”? int sum = 0; int [] paychecks = { 180, 190, 180, 230, 220 }; int index = 0; while (index < 4) { index = index + 2; sum = sum + paychecks[index]; } // If you got sum == 400, you were right. Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 20 (index 2 + index 4)

array Example 6 – with error // What is the final result of “sum”? int sum = 0; int [] paychecks = { 180, 190, 180, 230, 220 }; int index = 0; while (index <= 4) { index = index + 2; sum = sum + paychecks[index]; } // This is an example of an out-of-bounds // error, trying to access an index of an array. Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 21 The error here is subtle, but this is exactly what trips students up for hours debugging. Note how index will be 4 IN the second loop, but 6 IN the third loop! This will be an error.

Quick note on the String class A “String” is just another type of object. It is made up of all the characters between double quotes “”. Only tricky thing is that the backslash “\” cannot be used alone. It denotes an “escape” character and is used in various ways. Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 22

Typical Strings String name = “Scott”; String a = “is A”; String z = “zing!”; String mommy = “ma”; // You can “concatinate” strings together … // in other words add the strings together. String myInstructor; // Homework: What is the value of myInstructor??? myInstructor = name + a + mommy + z; Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 23

Lab this week Please make sure you complete chapters 1-5 this week. Work on your projects. You will be shown how to submit your project. – Includes “zipping” up your project directory – Submitting it through the Assignments page on UBLearns – There is a document on UBLearns – Course Documents section that shows you how to submit Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 24

CHAPTER 1-5 SUPPLIMENT Section 4 Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 25

There are methods in crab-world that I cannot use in my project? Why? Let’s take a look at the crab world class hierarchy: Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 26 The code in here, comes with Greenfoot. You cannot see or edit this code, BUT you can subclass the class and use the methods from that class.

Let’s take a look at the Actor class Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 27 OMG, do I have to know what to do with all this now??? No, instead let’s reuse another person’s work!!!

So if I don’t use Actor, what can I use? Let’s look again at the crab-world hierarchy: Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 28 Interesting, maybe the Animal subclass has methods I could use and then don’t have to write myself!!!

I don’t see the Animal class in the java docs?! The Animal class is not part of Greenfoot, it is just a subclass of Actor (which is a part of Greenfoot). It uses (inherits) methods from Actor, that may be more complicated to understand, and simplifies them for use. If you want to take advantage of this already written and debugged code, you have two choices: – You can cut/paste code from “Animal” into your classes. – Or you can sub-class the Animal class into a new class, thereby inheriting all the hard work someone else has done! Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 29

Let’s take a look at the Animal class Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 30 Oooh, now this is a useful method. I can detect if my “Frogger” hero is overlapping an obstacle. And I don’t need to write any code to use it, I can just inherit it!! Woot!

ADDITIONAL MATERIAL Section 5 Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 31

What picture file formats are we supposed to use? You can use any of the supported file formats: JPEG, PNG, GIF, BMP, or TIFF These should be placed in your project directory in a subdirectory called “images” Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 32

What file type would you use? If you are using or creating your own files, you will want to use the PNG file format. – It allows transparency, so that you don’t have a case of the “blockies”: – but instead have this: Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 33

How does PNG work then? GIF and PNG files use a “transparency color”. – One color value is designated as a transparent pixel. – That color value is usually a color that goes unused, like magenta. The problem is that you may still get “jaggies” around your image, since the edge pixels do not blend with the background perfectly, but at least you won’t get a big white box around your image. Monday, Oct. 3rd, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 34