CS51 - Spring 2010 - Lecture 1
introduction to students
- name
- major (or expected major), year
- CS background
- Why are you taking this course?
- What do you hope to get out of the course?
Discuss with your neighbor...
- What is computer science?
- computer science is more than programming
- study of computers
- solving problems using computers as the tool
- What are computers good at?
- Following well defined, unambiguous set of instructions (algorithms)
- Computers can do the same thing over and over again exactly the same way
- What aren't computers good at?
- Computers can only do what they're told (via the program)
Goals of the class
- introduction to computer science...
- design, code and debug medium-sized programs in Java
- basic analysis of programs for correctness and efficiency
- Pacman (test program from last year)
Administrative
- Course web page:
http://www.cs.pomona.edu/classes/cs051/
- Textbook - need to get it
- Labs - required!
- All handouts, labs, assignments, etc. will be posted on the course web site
- Late policy
- Grading
- Academic honesty
Style of the course
- interactive!
- ask lots of questions
- participate
- be expected to do group work in class
- show lots of demos
show
MakeBox code
- Eclipse IDE (Integrated Development Environment)
- Computer programs are written in computer languages (in our case Java). These are high-level instructions that people can understand. Programs are then compiled (or translated) into more basic instructions for the computer to execute.
- What do you think this program does?
- comments, either // or /*
- The IDE uses colors to help distinguish different types of text in the program
- Programs use a variety of "special words" in the language (often indicated in red/maroon by the IDE). I'll explain these along the way, but some you'll just have to ignore for now.
- What would you need to specify to draw shapes (and text) on the screen?
- "new" keyword creates a new object (an instance of a class) and is called the "constructor" of the object
- new FilledRect(x_location, y_location, width, height, canvas);
- new FramedOval(...) defines the bounding rectangle around an oval
- new Line(x_start, y_start, x_end, y_end, canvas)
- new Text(text_to_display (in quotes), x_start, y_start, canvas);
- coordinate system starts in the upper left hand corner with positive x to the right and positive y down
- curly braces denote blocks of text that go together
- here we have three main blocks
- semicolons (;) denote the end of a "statement" or one step for the computer to execute
- header of the class (MakeBox)
- public class <class_name> extends WindowController
- body of the class is defined by the curly braces
- Class: a set, collection, group or configuration containing members regarded as having certain attributes or traits in common.
- classes contain methods: ours has two
- method headers:
- public void begin()
- public void onMousePress(Location point)
- methods denote a chunk of code that will be executed together at the same time
- when do you think these methods will be called/invoked?
- What other mouse handling methods do you think we have?
- onMousePress(Location p)
- onMouseRelease(Location p)
- onMouseClick(Location p)
- onMouseMove(Location p)
- onMouseDrag(Location p)
- onMouseEnter(Location p)
- onMouseExit(Location p)
show
MakeBox demo
show
UpDown demo
- what do you see here?
- two text strings (UP and DOWN)
- x coordinates should be the same
- y coordinate different
- which method should these be created in?
- what other methods should we have?
- onMousePress
- set color of each text
- onMouseRelease
- set color of each
Variables
- allow us to label/name something so that we can refer to it later
- before you can use a variable, you must declare it
- put it inside the class body (these are called instance variables)
- private <variable_type> <variable_name>;
- we assign values to variables using '=' (which is different the '=' in math)
- instance variables can be used in ALL methods inside the class and in different calls to the same method
- besides being a label for something, variables are associated with object, that have attributes and associated methods
show
UpDown code
- two private instance variables
- called instance variables because we get a copy of each one for instance (object) of the class that we create
- setColor is a method associated with the class Text
show
Spirograph demo
- What's going on?