COMP-202 Introduction to Computing

Section 3, Winter 2007

Jun Wang
School of Computer Science
McGill University

Lecturer

Email: jwang90@cs.mcgill.ca

Office: McConnell Room 107

Office hours: Monday: 3:30 - 4:30; Wednesday: 2:00 - 3:00

Announcements

  • All questions related to assignment grading should be directed to
    guven.bolukbasi@mail.mcgill.ca

  • Apr. 17, 2007
    -- Schedule for the final tutorial is available on WebCT.

  • Apr. 11, 2007
    -- Special office hours: Apr. 24 & 25, 3-6pm, McConnell 107.

  • Mar. 28, 2007
    -- Friday, Mar. 30, Dr. Pientka is giving a talk on undergraduate programs in Computer Science.

  • Mar. 23, 2007
    -- The program Insert.java (in-class exercise on Mar 23) posted.

  • Mar. 21, 2007
    -- The program Frequency.java (in-class exercise on Mar 21) posted.

  • Mar. 19, 2007
    -- The program RecordsTest.java (in-class exercise on Mar 19) posted. Try it out and make sure you understand how it works.

  • Mar. 16, 2007
    -- The program GInput.java (input through a pop-up window) posted.

  • Mar. 12, 2007
    -- The program ParameterPassing.java (in-class exercise on Mar. 12) posted. Try it in Dr. Java and make sure you understand the results.

  • Mar. 7, 2007
    -- The program MonteCarloPI.java (in-class exercise on Mar. 5) posted.

  • Mar. 5, 2007
    -- Midterm review tutorial runs till Tuesday, March 6. Schedule on WebCT.

  • Mar. 2, 2007
    -- Assignment #4 posted.

  • Feb. 26, 2007
    -- The program StrStats.java (in-class exercise on Feb. 26) posted.
    -- Posted a list of exercises.

  • Feb. 16, 2007
    -- The program EstmPi.java (in-class exercise on Feb. 16) posted.

  • Feb. 12, 2007
    -- Assignment #3 posted.

  • Feb. 7, 2007
    -- Assignment #1 solution posted.
    -- Solution to a problem with the nextLine() method is posted. Follow the link below in "Relevant information".

  • Jan. 29, 2007
    -- Assignment #2 posted.

  • Jan. 24, 2007
    -- Classroom is changed to ENGTR 0060, effective Jan. 26, 2007.

  • Jan. 16, 2007
    -- Tutorial 3 to be held from Thursday, Jan. 18, to Tuesday, Jan 23.

  • Jan. 12, 2007
    -- Assignment #1 posted.
    -- TA office hours start Monday, Jan. 15.

  • Tutorial 2 to be held from Thursday Jan. 11 to Tuesday Jan 16. Check WebCT for schedule.
  • Tutorial 1 to be held in ENGTR 3070.
    Schedule has been updated. Always check webCT for the latest changes.
    • Monday, Jan. 8, 2007: 14:00-15:00, 16:00-17:00
    • Tuesday, Jan. 9, 2007: 13:00-14:00, 16:00-17:00
    • Wednesday, Jan. 10, 2007: 8:00-9:00, 17:00-18:00

Relevant information

Design classes from scratch

A list of exercises

Exercises

Some common problems

Installing J2SE 5.0

Installing the JDK

  • Go to http://java.sun.com, from popular downloads, select Java SE. Click on Previous Releases to look for J2SE 5.0.
  • Download JDK5.0 Update 10 .
  • Under Windows, the setup procedure by default uses the path
    C:\Program Files\Java\jdk1.5.0_10. It is recommended NOT to accept this default and instead use something like C:\Java\jdk1.5.0_10.

Setting the execution path

  • In Windows NT/2000/XP, start control panel, select System, Advanced, then Environment Variables. Go through the User Variables or System Variables window until you find a variable named PATH. Add you Java installation path name to the beginning of the path, so it looks something like this:
    C:\Java\jdk1.5.0_10\bin;other stuff
  • In UNIX, assuming your installation path is /usr/local/jdk5.0/bin , if you use C shell or tcsh, add the following line to your ~/.cshrc file:
    set path=(/usr/local/jdk5.0/bin $path)
    If you use bash, then add the following line to ~/.bashrc or ~/.bash_profile file:
    export PATH=/usr/local/jdk5.0/bin:$PATH

Testing your installation

  • Start a shell window and type the following command:
    java -version
    If you get error messages, go back to previous steps. Otherwise, congratulations!

Example programs

  • Exercise.java. This program gets 2 integers from user and prints the bigger number and the difference of the 2 numbers. Posted Jan. 17, 2007.
  • Newton.java. This program implements Newton's algorithm for calculating the square root of a number. It uses a simple while-loop. Posted Jan. 19, 2007.
  • Expectation.java. This program uses a while-loop to calculate 1/2 + 2/4 + 3/8 + 4/16 + 5/32 + ... + n/2#n, where n is an int we get from user, and 2#n is used here to denote the n-th power of 2. Posted Jan. 26, 2007.
  • EstmPi.java. This program calcuates an approximation of PI using the fact that the integration of 1/(1+x*x) over (0,1) is equal to PI/4. Posted Feb. 16, 2007.
  • StrStats.java. This program gets a string from user and finds out the number of vowels and consonants in the string. Empty string is not allowed, but we assume the string contains only lower-case letters and spaces. Posted Feb. 26, 2007.
  • MonteCarloPI.java(requires Circle.java and Point.java). This program estimates the value of PI by generating points whose x- and y-coordinates are in the range (0, 1). We create a circle centered at (0.5, 0.5) with a radius of 0.5. The ratio of the number of random points that lie inside the circle to the total number is approximately the ratio of the area of the circle to the area of the unit square: PI/4/1. Posted Mar. 7, 2007.
  • ParameterPassing.java. This program demonstrates how parameter passing works. Posted Mar. 12, 2007.
  • GInput.java. This program demonstrates how to get user input through a pop-up window (Note this is beyond the scope of the course). Posted Mar. 16, 2007.
  • RecordsTest.java. This program demonstrates how to use an array as an object's field. Posted Mar. 19, 2007.
  • Frequency.java. This program tests the random number generator by generating n numbers between 0 and MAX-1 and displaying the number of times each of the MAX numbers has been produced. Posted Mar. 21, 2007.
  • Insert.java. This program tests on average how many moves are required to inser a number into an array that is already sorted. Posted Mar. 23, 2007.

Lecture notes

Week 1

Week 2

Week 3

Week 4

Week 5

Week 6

Week 7

Week 8

A well-deserved break.

Week 9

Week 10

Week 11

Week 12

Week 13

Week 14

Week 15

  • class cancelled - Apr. 9, 2007
  • lecture 37 - Apr. 11, 2007