Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 100Lecture 11 Welcome to CS 100 n Goal: Learn to write intelligible, correct computer programs n Language: Java (but the language should not be the.

Similar presentations


Presentation on theme: "CS 100Lecture 11 Welcome to CS 100 n Goal: Learn to write intelligible, correct computer programs n Language: Java (but the language should not be the."— Presentation transcript:

1 CS 100Lecture 11 Welcome to CS 100 n Goal: Learn to write intelligible, correct computer programs n Language: Java (but the language should not be the primary focus) n Software: CodeWarrior n Plan: Compressed, intense version of a full-semester course. Be sure to keep up!

2 CS 100Lecture 12 Course Staff n Instructor: Lynette Millett, millett@cs n TAs: – –Wei Tsang Ooi, weitsang@cs.cornell.edu – –Alan Renaud, ajr5@cornell.edu – –David Welte, dcw6@cornell.edu n Consultants: – – Rocky Chen, pjc4@cornell.edu, Young Ho Cho, yc102@cornell.edu, Amanda Waack, amw18@cornell.edu

3 CS 100Lecture 13 Logistics n Lectures every day (Mon-Fri) n Roughly two assignments per week –NO LATE ASSIGNMENTS ACCEPTED n 0 or more short quizzes per week n Partners: 1 partner allowed where specified n Highest level of academic integrity expected

4 CS 100Lecture 14 Logistics continued n Office hours: as noted on web n One prelim: Monday, July 19, 1999 n Final Grades: –50% assignments –25% prelim –25% final n First Assignment due this THURSDAY

5 CS 100Lecture 15 When Turning in Assignments: n No late assignments accepted n Your name and Cornell ID# should be on frontpage (in comments, if a program) n For programming assignments turn in printout of source code, sample output and disk n For written assignments: please type. TAs reserve right not to grade illegible homework.

6 CS 100Lecture 16 Main Concepts Today n What is an algorithm? n Method and method call n Reading this week: Chapter 1 (skim), Chapters 2 and 3 n Handouts

7 CS 100Lecture 17 Algorithm n A set of instructions for performing some task that is: –precise –unambiguous –effective –abstract n In other words: well-specified

8 CS 100Lecture 18 Examples of Algorithms n A recipe for chocolate mousse n Given this list of integers, tell me which ones are even n Play a game of tic-tac-toe in a way that you never lose n Find your Star Wars name

9 CS 100Lecture 19 Star Wars example: n First SW name: Write first 3 letters of your last name then attach first 2 letters of your first name n Last SW name: Write first 2 letters of mother’s maiden name and attact first 3 letters of hometown Lynette Millett born in Norway, ME to I. (Rogers) Millett becomes: Mil+Ly = Milly Ro+Nor = Ronor

10 CS 100Lecture 110 Ambiguous Algorithm n Take two pieces of bread n Put peanut butter on one side of one piece n Put jelly on one side of the other piece n Put the pieces together n Output of this algorithm is....

11 CS 100Lecture 111 A Messy Sandwich n Why? n The algorithm did not specify that the pieces of bread should be put together so that the peanut butter and jelly are on the inside n Computers do exactly what they’re told or, worse, something undefined n Precision is important n Any other ambiguities in that example?

12 CS 100Lecture 112Programs n A program is an algorithm written in some language: English, C++, Java,.. n “Computer program” is a program in a computer language such as Java n Abstraction vs. Representation –Algorithm -- Program –Number -- Numeral –Object having “threeness” -- 3, III, three, |||

13 CS 100Lecture 113 How does it work? n Algorithm given as sequence of instructions to execute in order n In Java, each instruction is called a statement n Common statement in Java is a method call or method invocation n But, what’s a method? n “Method”, “procedure”, “function” often used interchangeably

14 CS 100Lecture 114 Sample Method Heading // Draw a line from point (x1, y1) to point //(x2, y2) public void drawLine (int x1, int y1, int x2, int y2) –Comment: explains the method precisely in English. Always begin with “//” –Prefix modifiers public, void (will explain later) –Method name: drawLine –Parameters: x1, y1, x2, y2, and their types: int

15 CS 100Lecture 115 Method Call Call: drawLine(3, 5, 1, 1); Call: drawLine(3, 5, 1, 1); n Command to be executed: Draw a line from point (3,5) to point (1,1) // Draw a line from point (x1, y1) to point //(x2, y2) public void drawLine (int x1, int y1, int x2, int y2)

16 CS 100Lecture 116 Another Example Call: printMax(7, 83, 20*5-52); Call: printMax(7, 83, 20*5-52); n Command to be executed: print the largest of 7, 83 and 20*5-52 n Note: the method name “printMax” has no meaning to Java. It is just a string of characters. We could have called it aaa, pm, mymethod, etc... // Print the largest of x, y and z public void printMax (int x, int y, int z)

17 CS 100Lecture 117 Yet Another Example Call: printHello(); Call: printHello(); n Command to be executed: In the output window, skip a line and print “Hello!” // In the output window, skip a line and print // “Hello!” public void printHello()

18 CS 100Lecture 118 Points to Remember n A method can have zero parameters n Syntax of a method call is: name ( list of 0 or more arguments separated by commas ) ;

19 CS 100Lecture 119 What does the Method do? n To find out what a method does: –Make a copy of the specification (the comment in the heading) –replace all parameters by the appropriate arguments in the call n This assumes the programmer wrote good comments

20 CS 100Lecture 120 Understanding Methods n The way we have understood these methods relies on comments that are –precise –understandable –correct n Your programs will be judged partially on how well your documentation is

21 CS 100Lecture 121 Reading n From now on, consult syllabus and/or webpage. We will try to point out appropriate readings from the text, but you should use the text as a reference when solving homework problems. n URL: http://www.cs.cornell.edu/cs100-su99

22 CS 100Lecture 122 Assignment W1 n Series of questions requiring written answers n Should be fairly straightforward if you’ve done the reading n Due Thursday July 1 at the beginning of class

23 CS 100Lecture 123 Registration Form n Please fill out and turn in before you leave class today.


Download ppt "CS 100Lecture 11 Welcome to CS 100 n Goal: Learn to write intelligible, correct computer programs n Language: Java (but the language should not be the."

Similar presentations


Ads by Google