CS100J 22 February 2005 More on Methods. Developing methods

Slides:



Advertisements
Similar presentations
Lecture 2 Introduction to C Programming
Advertisements

Week 2: Primitive Data Types 1.  Programming in Java  Everything goes inside a class  The main() method is the starting point for executing instructions.
1 CS100J 13 March 2006 Arrays. Reading: Secs 8.1, 8.2, 8.3. Listen to the following lectures on loops on your Plive CD. They are only 2-3 minutes long,
What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
1 CS100J 14 March 2006 Arrays. Reading: Secs 8.1, 8.2, 8.3. Listen to the following lectures on loops on your Plive CD. They are only 2-3 minutes long,
0 CS100J September 2007 CS100J: 12 weeks programming using Java, 2 using Matlab. David Gries. CS100M: 7 weeks of Matlab and 7 of Java. Daisy Fan. CS100H:
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
CS100J 17 March 2005 Arrays. Reading: Secs 8.1, 8.2, 8.3. The last Java feature to study in this course Quote for the Day: Computer science has its field.
1 CS100J 18 September 2007 More on Methods. Developing methods. Also: The inside-out rule; and the use of this and super. Read sec. 2.5 on stepwise refinement.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
1 CS100J 20 September 2005 More on Methods. Developing methods Also: About the use of this and super Read section 2.5 on stepwise refinement Listen to.
1 CS1130 Spring 2011: David Gries & Walker White Transition to Object-Oriented Programming Assumes programming knowledge in a language like Matlab, C,
CIS3931 – Intro to JAVA Lecture Note Set 3 19-May-05.
Course A201: Introduction to Programming 09/09/2010.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Week 2 - Monday.  What did we talk about last time?  Software development  Lab 1.
1 CS Sept 2010 Customizing a class Quote for the day: I have traveled the length and breadth of this country and talked with the best people, and.
1 CS1110 Lecture Sept Developing (String-processing) programs; class Vector; wrapper classes Prelim: 7:30-9PM Thursday 7 October. Last name A-K:
CS100J Spring 2006 CS100J: 11 weeks of programming using Java and 2 weeks using Matlab. David Gries is teaching CS100J. Graeme Bailey is teaching a special.
3 - Variables Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
1 CS1110 Fall 2011 David Gries, Steve Marschner Reading for this lecture and previous lecture: Sections 1.1, 1.2, 1.3. Lab 1 will give you practice with.
Moderate Problem. Problem  Write a function to swap a number in place without temporary variables.
Coming Up: Today: Review Quiz 2 Lecture on Section 2.4: Word problems! NOTE: This homework is due at the beginning of the next class session. Coming up.
1 CS1100 Fall Instructor: David Gries CS100M: Matlab No prior programming experience One semester of calculus Math & engineering type problems CS100J:
1 CS100J Classes, stepwise refinement 14 Feb 2007 Rsrecah on spleilng Aoccdrnig to a rscheearch at Cmabirgde Uinervtisy, it deosn't mttaer in waht oredr.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
1 CS1110 Classes, stepwise refinement 17 Feb 2009 Miscellaneous points about classes. More on stepwise refinement. Next: wrapper classes. Section 5.1 of.
COMP Loop Statements Yi Hong May 21, 2015.
1 CS1110 Classes, stepwise refinement 12 Feb 2009 Rsrecah on spleilng Aoccdrnig to a rscheearch at Cmabirgde Uinervtisy, it deosn't mttaer in waht oredr.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
WELCOME To ESC101N: Fundamentals of Computing Instructor: Ajai Jain
What time is it ? in the morning / in the afternoon in the evening
1 CS100J Spring Instructor: David Gries CS100M: Matlab No prior programming experience One semester of calculus Math & engineering type problems.
CS/ENGRD 2110 FALL 2013 Lecture 3: Fields, getters and setters, constructors, testing 1.
Coming Up: Today: Review Quiz 2 Lecture on Section 2.4: Word problems! NOTE: This homework is due at the beginning of the next class session. Coming up.
1 CS Sep 2011 Miscellaneous points about classes. More on stepwise refinement. Next: wrapper classes. Section 5.1 of class text Need Help? Make.
1 CS February 2009 Inside-out rule; use of this and super Developing methods (using String ops). Read sec. 2.5 on stepwise refinement Listen to.
Mean Mean  = Sum of all the values The number of values Eg. Find the mean of the following values: 2, 5, 4, 7, 5, 7, 8, 4, 5, 6, 12, 2, 4, 5, 7, 5 Mean.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
1 CS Sept 2010 Customizing a class Quote for the day: I have traveled the length and breadth of this country and talked with the best people, and.
CORRECTNESS ISSUES AND LOOP INVARIANTS Lecture 8 CS2110 – Fall 2014.
Pre-Calculus Section 8.6A Counting Principles. 1. Eight pieces of paper are numbered 1 to 8 and placed in a box. One piece of paper is drawn from the.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Recursion (Continued)
Week 2 - Wednesday CS 121.
UMBC CMSC 104 – Section 01, Fall 2016
CS1110 Spring Instructor: David Gries
CSE 220 – C Programming C Fundamentals.
CS/ENGRD 2110 Fall 2017 Lecture 3: Fields, getters and setters, constructors, testing
INC 161 , CPE 100 Computer Programming
Introduction to Computer Science / Procedural – 67130
Introduction to programming in java
CS1110 Classes, stepwise refinement 23 Sep 2009
CS1110 Wrapper classes, stepwise refinement 23 Feb
Lecturer CS & IT Department UOS MBDIN
DAYS OF THE WEEK.
1) C program development 2) Selection structure
2-3 Trees and the real world and…
CS1110 Lec Oct 2010 More on Recursion
Week of March th grade.
Homework Starting K&R Chapter 5 Good tutorial on pointers
15 Minute Math This presentation will review different math skills that will help you with every day math problems. Each lesson takes approximately 15.
CS100J CS100M is in Kimball Bll.
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Thinking about programming
In this class, we will cover:
Variables and Computer Memory
Review of Previous Lesson
Introduction to Western Civilization
Presentation transcript:

CS100J 22 February 2005 More on Methods. Developing methods Read section 2.5 on stepwise refinement Listen to PLive activities 2.5.1 -- 2.5.4!! Quotes that relate to specifying a method before writing it. A verbal contract isn't worth the paper it's written on. What is not on paper has not been said. If you don't know where you are going, any road will take you there. If you fail to plan you are planning to fail.

Prelim on Thursday evening, 7:30 to 9:00 On Thursday, Gries is out of town (at a conference of SIGCSE --Special Interest Group on Computer Science Education.) Two TAs will take his place. Thursday’s lecture will be devoted to a review for the prelim. You can ask questions; if you don’t, the TAs will lecture on what they think is important. They know what is on the test. The test will be graded Sunday afternoon and the grades posted directly after that. This week’s lab: devoted to the development of functions that deal with Strings. It is useful practice for the prelim.

Anglicizing an integer /** = the English equivalent of n, for 1 <= n < 1,000 e.g. ang(3) is “three” ang(412) is “four hundred twelve” ang(762) = “seven hundred sixty two” */ public static String ang(int n) Hint at how to do it. When we add 5 + 3 + 2 + 8, we start with x = 0 and add one value to x at a time, step by step: x= x + 5; x= x + 3; x= x + 2; x= x + 8; Definition of x: x is the sum of the values added so far. Can we start with String variable s = “” and step by step catenate pieces on to the end of it? What’s the definition of s?

Anglicizing an integer /** = the English equivalent of n, for 1 <= n < 1,000 e.g. ang(3) is “three” ang(641) is “six hundred forty one” */ public static String ang(int n) Start with String variable s = “” and step by step catenate pieces on to the end of it? Use two local variables, s and k. s k start: “” 641 “six hundred” 41 “six hundred forty” 1 end “six hundred forty one” 0 s start: “” “six hundred” “six hundred forty” end “six hundred forty one” Definition of s and k: ang(n) is s + ang(k) To find ang(n), anglicize k and append the result to s.

Anglicizing an integer /** = the English equivalent of n, for 1 <= n < 1,000 e.g. ang(3) is “three” ang(641) is “six hundred forty one” */ public static String ang(int n) { // ang(n) is s + ang(k) String s= “”; int k= n; } You are expected to study section 13.4! This definition of s and k is very important. This definition will drive the development. Whenever we append something to s, we have to change k to keep the definition true. The definition helps us develop the method body and helps the reader understand it. Whenever you declare a local variable whose value will change often over execution of the method, write a comment near its declaration to define it!! You will use the definition often as you develop the method. Without the definition, you will forget what the variable means and will make mistakes.

Anglicizing an integer /** = the English equivalent of n, for 1 <= n < 1,000 e.g. ang(3) is “three” ang(641) is “six hundred forty one” */ public static String ang(int n) { // ang(n) is s + ang(k) String s= “”; int k= n; } The rest of this lecture is devoted to the development of this algorithm, using DrJava. The final program will be put on the course website before 7AM Wednesday morning.