Spring Semester 2002

Sat May 4

Tue Apr 30
Exam Tonight Rawles 5-7pm

Mon Apr 29
Here's a review sheet from summer that would be a good review for tomorrow also.

Fri Apr 26
1. Sat Apr 27 I will have office hours from 2-4pm in LH016.

2. Sun Apr 28 I will have office hours 6-8pm in LH016.

Thu Apr 25
Here's a sample review sheet for the final:

1. A final exam from the past.
2. Another final exam from the past.
3. More to come soon (warmups, such as this, with solutions, from the book).

Here's the code for the game.

Here are some notes that build towards it:

Here's to get us started on I/O and basic networking.

Tue Apr 23

WHAT
Midterm Two Make-Up
WHEN
Tuesday April 23

WHERE
SWAIN WEST 119

WHAT TIME
7:15pm - 9:15pm

Sun Apr 21
Let's briefly talk about the example so cleverly brought up by Alex Basyrov:
(1 + 1) * 2 + 2 * ( 1 + 1 )
Our substitution rules need to be revised once the parens are added. Parens can delay the evaluation of operators (such as "*") and when that happens we need to propagate this delay throughout. So, in our case, we only need to take care of pluses and minuses, which should not be evaluated if there are stars and slashes waiting to be processed (they bind stronger to the numbers than their lower precedence counterparts).

So the code more or less becomes (only an if statement changes):

static boolean reducePlusesAndMinuses(Vector expr) {
boolean done = true;

for (int i = 0; i < expr.size(); i++) {

if (expr.elementAt(i).equals("+") || expr.elementAt(i).equals("-")) {

if (
// value to its left
isValue((String)expr.elementAt(i - 1)) &&
// value to its right
isValue((String)expr.elementAt(i + 1)) &&

// and not a higher priority operator to wait on
! ( ( // value on left not at end of vector
(i - 2) >= 0 &&
// higher precedence operator waiting there
( ((String)expr.elementAt(i - 2)).equals("*") ||
// note there are two such operators
((String)expr.elementAt(i - 2)).equals("/")
)

) // this can happen on the left

|| // or (it can happen on the right)

( // value on right not at end of vector
(i + 2) < expr.size() &&
// higher precedence operator waiting there
( ((String)expr.elementAt(i + 2)).equals("*") ||
// note there are two such operators
((String)expr.elementAt(i + 2)).equals("/")
)

)
)

) {

Integer a = new Integer((String)expr.elementAt(i - 1));
Integer b = new Integer((String)expr.elementAt(i + 1));

// ... reduce the plus sign
You should include this change in your programs.

Fri Apr 19
Here's the code developed in lecture on Thursday.

Second Midterm MAKE-UP EXAM will likely be held in

Swain West 119 on
Tue Apr 23 7:15pm-9:15pm.
Confirmation to be posted here soon.

Thu Apr 18
Congratulations to Alexander Basyrov for providing this test case for Homework Six:
(2+4)*2+3*(3+7)
Now the question is: why is this interesting; and if it is, then what?

Wed Apr 17
Thanks to Adam Justice (today) and Courtney Gavin (yesterday) for helping produce the following code that's a good start for the last homework and close to what we will develop in class tomorrow. (If I change it a bit tomorrow I will post that code too). The emphasis here is on understanding what it takes to first develop a strategy (procedure, algorithm) and then to instruct the computer to behave that way.

import java.io.*;
import java.util.*;

class Eval {

/* this Hashtable must be shared between two static methods
(main, which creates it and process, which is using it
for lookup,) so it must be global enough */
static Hashtable env = new Hashtable();

// here's the main method getting away with a try/catch
public static void main(String[] args) throws IOException {

//this is why we need to acknowledge the IOException

//checked after the loop, must be visible enough
String line;

do {
//prompt
System.out.print("Eval> ");

//stop if you have to
if (line.equals("bye")) break;

//get ready to take things apart
StringTokenizer st = new StringTokenizer(line);

//prepare the storage for the resulting tokens
Vector v = new Vector();

//and now just do it
while (st.hasMoreTokens()) {
}
//so now the tokens are in a Vector, v

//could be an assignment statement
if (v.size() > 2 && v.elementAt(1).equals("=")) {

//in which case you take the name at the front
String name = (String)(v.elementAt(0));
//... and keep it in the variable called 'name'

//then remove the string and the equal sign
v.removeElementAt(1);
v.removeElementAt(0);
//the Vector is shrinking as you remove elements so,
//either remove backwards or twice at index 0 (zero)!

//now process the remaining expression and store the
// value in the Hashtable in the entry for the name
// you found in position 0 in the original Vector
env.put(name, Eval.process(v));

} else {// if it's not an assignment statement,

// ... then you can start evaluating it
Eval.process(v);

}//end of conditional processing

// getting ready to report the result
System.out.print("Done: ");
Eval.show(v); //the Vector is shown here

} while (true);//loop if you have to (exit with break!)

}// end of main

// straghtforward procedure for showing a Vector
static void show(Vector v) {
for (int i = 0; i < v.size(); i++) {
System.out.print(" " + v.elementAt(i));
}
System.out.println();
}

// this is the heart of the evaluator
static String process (Vector v) {// receives the Vector as a param

// wishful thinking (see do/while test below)
boolean finished = true;

// first replace identifiers by their values
for (int i = 0; i < v.size(); i++) {
// get the String that's there (position i)
// this could be anything: +, -, 123, a, *
String element = (String) (v.elementAt(i));
// look it up in env (nevermind how it got there)
Object value = env.get(element);
// if you find it, there's a value associated with
if (value != null) {
// replace it (index i) by the value it has
v.setElementAt((String)value, i);
}

}// all identifiers have been replaced

// we're ready for the real processing

do {

// remove parens and update your agenda
finished = Eval.removeParens(v);
// all three methods used here return true when
// they could not find anything to work on within
// the expression, and they return false if they
// could change it in at least one aspect; therefore
// your hope of being finished is true only when none
// of the workers find anything to work on...
finished = finished && Eval.removeStars(v);
finished = finished && Eval.removePluses(v);

// report the current status of the Vector
// from within the process of changing it
System.out.print("Processing: "); Eval.show(v);

} while (! finished); // if not finished keep going...

// return the first element in the resulting Vector
return (String) (v.elementAt(0));

}

static boolean removeParens(Vector v) {
// empty procedure, reports true
return true;
// this means it 'thinks' it's done...
}

static boolean removeStars(Vector v) {
// same here, you need to provide these methods...
return true;

}

static boolean removePluses(Vector v) {
// the only one that works
boolean done = true;// assume nothing will have to be done

// look everywhere in the Vector
for (int i = 0; i < v.size(); i++) {

// if you find a plus sign
if (v.elementAt(i).equals("+")) {

done = false; // there's work to be done

// expect two numbers on its sides
int n = Integer.parseInt((String) (v.elementAt(i - 1))),
m = Integer.parseInt((String) (v.elementAt(i + 1)));

// store the sum where the first operand was
v.setElementAt((n + m) + "", i - 1);
// carefully remove the plus and the second operand
v.removeElementAt(i + 1);
v.removeElementAt(i);

// don't skip the next token
i -= 1;
// the Vector has shrunk so it's in front
// of you, and the for loop will increment i by default

}// end of determining if you're looking at a '+' sign

}// end of the for loop

return done; // report whether we're done or not

}// end of the removePluses method

}// end of story

Tue Apr 16
Lecture notes for today posted, discuss double-buffering.

Mon Apr 15
Due date for Homework Five pushed to
Wed Apr 17
so we can talk about double buffering in class first.

Thu Apr 11
Lab notes for the week posted.

Grades for the Second Midterm have been posted this morning.

Tue Apr 9
Here's a(n older) solution to Lab Ten.

Lecture notes for the week posted.

Thu Apr 4
Answers to the questions on the exam last night posted.

Lecture, lab notes for today posted.

Wed Apr 3
MIDTERM EXAM TWO in Rawles 100 between 7-9pm.

The test is WEDNESDAY APRIL 3 (THREE), in RH100, between 7-9pm.

Tue Apr 2
Homework assignments 5 (Five) and 6 (Six) have been posted.

Mon Apr 1
Lecture notes for last Thu, this Tue, posted.

Sat-Sun Mar 30-31
QuizSite now has five more batches of questions that should help you get ready for the exam on Wednesday (April 3, 7-9pm, Rawles 100). Please also don't forget about the sample practice exam (same format, includes answers, in blue). Exam is open-book.

Fri Mar 29
Here's a practice midterm for next week.

Note that correct answers are included.

Thu Mar 28
Today we will start talking about inheritance, notes will be posted after the lecture.

Tue Mar 26
Lecture notes for today, lab notes for this week, posted.

Thu Mar 21

The average of practical grades was 80.82, with a standard deviation of 14.79.

Wed Mar 20
Here's a program written by Don Heintzman before the break. The problem is from Chapter 5, and was one of the problems on the Midterm Makeup Exam, and you can find it in the book on page 219, P5.2. The style of coding below is essentially what we need for this week's lab.
import java.io.*;

public class PracticalTest {
public static void main(String[] args) {

System.out.print("Enter the card notation: ");

String two = card(hand);
suit(two);
}

public static String card(String card) {
String one = card.substring(0,1);
String two = card.substring(1,2);

if      (one.equalsIgnoreCase("A"))  System.out.print("Ace of ");
else if (one.equals("2"))            System.out.print("Two of ");
else if (one.equals("3"))            System.out.print("Three of ");
else if (one.equals("4"))            System.out.print("Four of ");
else if (one.equals("5"))            System.out.print("Five of ");
else if (one.equals("6"))            System.out.print("Six of ");
else if (one.equals("7"))            System.out.print("Seven of ");
else if (one.equals("8"))            System.out.print("Eight of ");
else if (one.equals("9"))            System.out.print("Nine of ");
else if (one.equals("1"))  {
if (two.equals("0")) {
System.out.print("Ten of ");
two = card.substring(2, 3);
}
}
else if (one.equalsIgnoreCase("J"))  System.out.print("Jack of ");
else if (one.equalsIgnoreCase("Q"))  System.out.print("Queen of ");
else if (one.equalsIgnoreCase("K"))  System.out.print("King of ");
else System.out.print("Unknown denomination of ");

return two;
}

public static void suit (String two){

if      (two.equalsIgnoreCase("D")) System.out.println("diamonds.");
else if (two.equalsIgnoreCase("H")) System.out.println("hearts.");
else if (two.equalsIgnoreCase("C")) System.out.println("clubs.");
else System.out.println("unknown colour.");
}
}
This is based on the solution posted but it's using methods, as in Lab 8.

Tue Mar 19
Help with the new homework posted as Lecture Notes Twenty.

Mon Mar 18
Akshay's office hours this week only moved to Tue 1:30-3:30pm (same place).

Sat-Sun Mar 9-17
SPRING BREAK

Fri Mar 8
Friday office hours are between 5-6pm in LH016, as usual.

Lab Notes Nine and Lecture Notes Nineteen (for after the break) already posted.

Here's the code we developed in class yesterday.

class One {
public static void main(String[] args) {
int[] b;
System.out.print("Size> ");
b = new int[n];
Cookbook.show(b);
Cookbook.squares(b);
Cookbook.show(b);

b = Cookbook.insert(b, 3, 13);

Cookbook.show(b);

}
}

class Cookbook {
static void show(int[] a) {
for (int i = 0; i < a.length; i++)
System.out.print(a[i] + " ");
System.out.println();
}

static void squares(int[] a) {
for (int i = 0; i <= a.length - 1; i++) {
a[i] = (i + 1) * (i + 1);
}
}

static int[] insert(int[] x, int ind, int val) {

int[] temp = new int[x.length + 1];

for (int i = 0; i < ind; i++)
temp[i] = x[i];

temp[ind] = val;

for (int i = ind; i < x.length; i++)
temp[i + 1] = x[i];

return temp;

}

}

Thu Mar 7
Lab Notes Eight posted.

I have received a few messages asking me about this week's lab. This week we have labs as usual, except I am aware this week is a bit different, so let me explain what the difference is.

If you can't make it to the lab this week you will have to make it up the week after the break. The notes will be posted soon, in class you will be asked about the problems on the practical a week ago. That's basically it about the lab this week.

I am still working on the grades for the practical. I hope to have them posted at the end of the week at the latest. I have two more sections to grade. I'll try to post the grades for the makeup as well before the week is over.

Wed Mar 6
Midterm One Makeup in Rawles at 7pm.

Tue Mar 5
Lecture Notes Eighteen prepare us for Lab Assignment Eight, to be posted tomorrow.

Mon Mar 4
Homework Four posted, offers opportunity to work with loops and arrays.

Sun Mar 3
Lecture Notes for Tuesday posted.

Sat Mar 2
Review Notes for Midterm One Makeup posted.

Fri Mar 1
PRACTICAL EXAM in labs today.

Thu Feb 28
PRACTICAL EXAM today and tomorrow in labs.

In class we will continue to solve problems. Please keep up though with the posted notes. You have now seen most of Chapter Seven, and the notes for today summarize all known aspects. You have also seen recursion and the notes end with a neat example of using recursion to solve a difficult problem. You also should be in command of all of Chapter Three and the notes posted for the lecture two days ago go through the development of a Fraction type that should be instructive.Fractions are like BigIntegers (i.e., precise and neat).

Wed Feb 27
Review session tonight, solutions to all problems will be posted at the end.

The review session is in Rawles Hall at 7pm, we will solve problems.

Tue Feb 26
Here are the review exercises from chapter 6, with answers.

For problems from chapter 6 check the notes, and list of problems posted.

(Links to chapter 5 problems are in here, as you probably already know).

Mon Feb 25
Lab notes for this week contain a set of practice problems for the exam.

Lecture notes for tomorrow posted.

Sun Feb 24
Rawles 100 has been reserved for the following dates:

Wed Feb 27 7pm Practical Exam Review

Wed Mar 6 7-9pm Midterm One Makeup Exam

Sat Feb 23
Minute papers count being updated.

Also a reminder: documentation about all of the Java classes that will be used this semester available under Useful Links (click on Hierarchy). Sun's Java tutorial is available here.

Fri Feb 22
Documentation about the StringTokenizer can be found here.

Thu Feb 21
Lab Notes Seven, Homework Three, posted.

Wed Feb 20
Lecture notes for tomorrow solve problem 6.17 from your book.

Tue Feb 19
As we approach the Practical Exam the lecture notes become more oriented towards practical application of the knowledge we have acquired. Please read the web notes and work through them, and the book, as if they were extended lab notes. Reading the web notes and working through them can make a significant difference on your future exams in this class.

Mon Feb 18
Lecture notes for tomorrow posted.

Sun Feb 17
Minute papers count updated in Postem.

Sat Feb 16
A second version of Midterm One will be offered the week before Spring Break. The format will be different; I will have details soon. Everybody is welcome to take it, the exam is optional, but the highest of your two scores will be kept (if you have taken both exams.)

Fri Feb 15
Scores for the exam have been posted (A201-1219).

Here's the distribution of (raw) scores:

50 ***
49 ******
48 *******
47 ****
46 ********
45 ******
44 *******
43 ****
42 *****
41 *************
40 *********
39 *********
38 ********
37 ******
36 ********
35 ************
34 *******
33 *****
32 ****
31 *******
30 ****
29 ******
28 *******
27 ********
26 *****
25 ********
24 *****
23 ****
22 *******
21 *****
20 ****
19 **
18 *
14 **
The average was 34.92, the standard deviation was 8.72.

Thu Feb 14
Here's the exam you took last night, with answers.

Wed Feb 13
There's an exam tonight at 7pm in RH 100.

Please bring a pencil with you for the scantrons.

Exam consists of about 52 multiple-choice questions.

Good luck and see you tonight.

Tue Feb 12
First, I'd like to remind you that my office hours are 9-10am and 1-2pm MTWR, in LH201D, and 5-6pm on F in LH016. That's how it is every week throughout the semester, so please come if you need help. If you can't make these hours please make an appointment, I am sure we can find the time to offer you some help, whatever time would work best for you.

Second, when you approach the Practice Quizzes and the Sample Midterm please approach them as Learning Tools, not as instruments of testing. Use them to learn something new, not to measure how much you know. You should be happy if you cannot solve any of the problems by yourself at first, but are able to understand why the right answer is as indicated. This means that you have learned something in the process, that will help you on the exam.

Remember that the exam on Wednesday is open-book, open-notes, but individual work.

Mon Feb 11
Andrey Salaev joins the list of tutors, and Zhen adds extra office hours.

Sun Feb 10
Here's a sample midterm exam (from last summer).

Skip questions 31, 32, 38-42 (inclusive), 46, and 47.

All the others make for a very good study material for the exam on Wednesday.

Also, don't forget your exam on Wednesday is open-book, and open-notes.

Sat Feb 9
Lecture Notes Eleven, posted for Tuesday, are meant as a review for the exam.

Fri Feb 8
Minute papers updated, notes for next week posted.

Thu Feb 7
Here's a second approach to producing random numbers.

(This justification developed with Omar Khan during office hours).

Say we need random numbers between a, and b, where a is less than b. Let y be such a random number. Then we can calculate how far into the segment y is, as a percentage.

double p = (y - a) / (b - a); // [1]
Since y is random that means p can be anywhere between 0 and 1.

Well, such numbers can be generated with Math.random().

So, let's turn [1] on its head, to obtain y as a function of p.

Then, we have:

y = p * (b - a) + a;
Now replace p by Math.random():
y = (b - a) * Math.random() + a;
Same as stretching followed by a translation. End of story. Thanks, Omar.

Wed Feb 6
All links in Lecture Notes Ten are now working.

Please note the unusual date and time and procedure for turning in Lab Assignment Five.

Tue Feb 5
Here's a rewritten and updated summary of office hours.

Lab Notes for this week posted, contain Lab Assignment Five.

Mon Feb 4
Worthwhile observations courtesy of Florentina Tone in response to Lab Four:

1. The intersection method in class Rectangle does not return a valid (that is, meaningful) answer when the Rectangles don't overlap. (This is what the book says too, but one needs to read even the text of the problem with care!). So what do we do when they don't overlap and how do we know that in advance? The solution is to check if they overlap before you calculate the intersection (which you should do only if they overlap!).

2. The epsilon variable is needed in Fourteen of the Problem Set One (with solutions) so we don't divide by 0 (zero). But when x is negative and much smaller than epsilon the result is incorrect. What do we do? (This is problem P2.18 page 99 in the book). The trick is to think of the problem in physical terms: if you're really using a car and if in your calculations you use an epsilon that is small enough, e.g. about 0.1in (or smaller, like 0.001 of the car's length) then

1. for negative x above this small value the formula says: "You will make it!"
2. and for all practical purposes that's correct, since you can walk that distance
3. but we need to be aware of the approximation, we definitely need to!

Other than this "negative micron" case, the formula is perfect.

But does anyone have a formula that covers even this case with accuracy?

Sat-Sun Feb 2-3
Minute papers count updated.

Fri Feb 1
So far we have given an introduction to all primitive types, variables, expressions, and hinted that boolean type (through run-time tests) has potentially the greatest influence on the program's course of action. We've seen I/O with ConsoleReader and some simple, yet non-trivial programs. Don't forget the warmups and problems posted along with solutions!

Thu Jan 31
In class today we'll make sure Lab Three is understood, move on to Classes and Objects.

Wed Jan 30
Homework Two posted.

Tue Jan 29
Lab notes for this week posted, contain lots of solved problems, Lab Assignment Four.

Mon Jan 28

• Strings (Section 2.6, pp. 75-81)
• Decisions (pp. 184-186)
• The boolean primitive type (pp. 207-210)
• The char primitive type (pp. 731-733)
• An Introduction to Classes (pp. 103-120, 126-130)

By the end of the week we should have covered all of Chapter Three.

Sun Jan 27
Lecture notes 8, 9, and 10, have been posted.

Sat Jan 26
An updated syllabus has been posted.

Fri Jan 25
Please take a look at both practice quizzes posted in QuizSite.

Also, please let me know if you appear listed in the wrong section. If you are listed in the wrong section please send me an e-mail message so I can make the correction, and wait for a confoirmation from me before submitting your homework assignment.

Thu Jan 24
I'd like to refer to this picture in class today as we mention booleans.

Wed Jan 23
Here's a list of tutors for this class.

Tue Jan 22
Two sets of practice questions will be posted soon in QuizSite. These are supposed to help you with your regular lab and home work, as well as prepare you for the midterm exams.

Mon Jan 21
Update on the reading assignments and availability of Java 2 SDK software posted:
Date: Mon, 21 Jan 2002 13:16:45 -0500 (EST)
To: Undisclosed recipients:  ;
Subject: A201/A597/I210 Update

First of all if you receive this message in error please let me
know also so I can update my e-mail distribution list.

Dear A201/A597/I210 friends,

I went to the bookstore and bought a new book that comes with a
CD. On the CD there's Sun's Java 2 SDK. I just tried installing
it and it only took me a few minutes. Those who still can't get
Emacs or Sun's JDK installed from the web are welcome to borrow
this CD from me and use it to install SDK. (SDK is the new name
for JDK 1.3, so it's basically the same and with it you will be
able to run javac and java from the command line).

I also wanted to review the reading assignments from the book:

a) tomorrow in class we will do mostly 2.5, 2.6, 2.7, and solve
problem P2.19 (Problem 15 in the set posted with Lab Two Notes)
You would also do well to review some of the warmups (that have
also been posted with Lab Notes Two, with solutions). This last
set (of warmups) can be found in the book on pp. 92-94.

c) on Thursday we plan to introduce the boolean type as part of
our discussion on expressions, types, and operators. We'll talk
of warmups and programming problems at that time, also.

b) to review what has been already covered, one should focus on
sections 1.7-12, 2.1-3 (including Common Error 2.1, Quality Tip
2.1, Advanced Topic 2.1-4, Common Error 2.2 and Prod. Hint 2.1)

d) next week we start Chapter 3, user-defined classes. I posted
lecture notes Seven already, which correspond to sections 3.1-4
from the book.

Hope this helps. If you have questions, or if you need any help

Sat-Sun Jan 19-20
Lecture and lab notes for next week posted.

Fri Jan 18
Thanks to Andy Davis for pointing out a small typo at the end of Lab Notes Two.

The Lab Assignment is due next lab (Thu-Fri) as indicated on the What's Due? page.

Thu Jan 17
QuizSite has finally been initialized, please check during the lab.

(Please note we use dgerman-I210 for the name of the class account).

I am also going to assemble a list of A201 tutors.

Here's an interesting problem courtesy of Wendy Clendening:

public class Math {
public static void main(String[] args) {
int a = 5;
int b = 7;
System.out.println(Math.max(a, b));
}
}
This does not work. Why? (The answer will be provided in class).

Wed Jan 16
Here's a link to Sun's website for jdk1.3 (also known as Java 2). If you have this installed you can use Notepad, javac, and java to develop programs. Alternatively, you can download Emacs. (Here's a reference card for Emacs, to help you use it more effectively).

Remember that no editor (or any Java IDE for that matter) is Java. What we mean by Java is essentially encapsulated in two programs: javac and java. The rest is ancillary material related to development. But Emacs is the superior editor!

Tue Jan 15
Lab Two (including Lab Assignment Two), Homework One, schedule of homework assignments for the semester have been posted. Please note that Lab Assignment Two is composed of one problem and a set of warmups (with solutions). A set of problems (with their solutions) also posted in anticipation of next week's lab.

Please check the "What's Due?" page frequently also.

Mon Jan 14
As we start to study Java seriously this week here are two notes to guide us in our journey.

One is trying to describe the nature of programming as being a field in which (like any other science) solving problems (and enjoying it) is the way to go.

The other one is trying to put into a broader perspective the rigour (or precision) with which you will be confronted in this class, and in other classes, throughout your college years.

With your permission, I hope you find them useful.

Sun Jan 13
Links to notes from previous semesters: Sum 2001, Spr 2001, Sum 2000, Spr 2000.

The single most significant set of notes for this semester will be Sum 2001.

Sat Jan 12
I am sorry if you tried to find me yesterday and couldn't. I had to undergo an endoscopy in the morning and the medication didn't allow me to do anything for the rest of the day.

Fri Jan 11
Here's the Emacs installation tutorial.

Here's the link to Sun's website, as well.

Thu Jan 10
Lab Assignment One posted, due next week in lab.

Lecture notes for this week, next, lab notes for today, posted.

Wed Jan 9
Web site pages now refer strictly to the current semester.