|
Second Summer 2002 |
Sat Aug 10
I couldn't come to the final (and hence asked Richard to proctor it) because I was getting a hair cut. Then Richard came with the exams and I started grading. That was on Friday, at about 4pm (I remember it very well).The most shocking thing about getting a buzz cut (I didn't go all the way) is that you suddenly realize your head is much smaller than you ever would have imagined. I've developed a sudden fear of ping-pong. Unfortunately, my ears, nose and glasses (I've started wearing glasses, I just felt I had to) stayed exactly the same size thus giving me a Mr. Potato Head look that I hope will one day become fashionable.
On the plus side, I find endless amusement rubbing my head with my hand. You would think I'd get bored doing that, but you would be mistaken. That's why it's taken me so long to post the grades; I'm typing with one hand. It did take me a long time (essentially, half of Friday and all of Saturday) but now grades have finally been posted and I am sure we all appreciate that.
I try to resist rubbing my head, but I don't have the willpower. I tried to cut down from two hands to one. I discover myself afraid that this could be like a gateway habit, a stepping-stone to worse addictions. And I try to soothe my anxiety by rubbing my head, which only makes things worse.
I truly hope you have enjoyed this class. I tried to put the best I had in it, and make it accurate and informative, while keeping it entertaining to the extent that one could have hoped for. I enjoyed working with each and every one of you, and I wish you the best of luck in your future endeavors.
Of all the minute papers there was one that I will remember forever. It was written on Thursday, before the exam, and had no signature nor name on it. In clear handwriting it went straight for the heart:
Dear Professor, today I love you more than tomorrow.Have a great end of summer and my best of the best wishes to all of you.
![]()
Wed Aug 7Instructions for Students to complete CS evals through BEST:
1) Go to http://www.indiana.edu/~best/
2) Click on "Students" under "QuizSite"
3) Click on Instructor and Course drop-down box
4) Choose link to desired course evaluation
All choices are preceeded by "csci"
*LECTURE SECTIONS:
Lecture sections are preceeded by an upper-case letter
(ie: csci-A110)
*LAB SECTIONS:
Lab sections are preceeded by lower-case letter
(ie: csci-a110)
5) Choose "Do a Current Activity"
6) Highlight name of instructor you wish to evaluate
7) Click "Proceed" button
8) Answer the 30 questions and click the "SUBMIT" button.
9) **PLEASE REMIND STUDENTS TO CLICK THE SUBMIT BUTTON**
10) Repeat process for each additional lecture/lab instructor
Tue Aug 6But that means there will be no bonus extra problem either.
Mon Aug 5import java.util.*;
class Nine {
public static void main(String[] args) {
Hashtable h = new Hashtable();
h.put("a", "5");
h.put("b", "6");
String expr = "a + b";
StringTokenizer st = new StringTokenizer(expr);
while (st.hasMoreTokens()) {
String t = st.nextToken();
if (h.get(t) != null) System.out.println(h.get(t));
else System.out.println(t);
}
}
}
Sun Aug 4import java.util.*;
class Six {
public static void main(String[] args) {
ConsoleReader in = new ConsoleReader(System.in);
while (true) {
System.out.print("Six>");
String line = in.readLine();
if (line.equals("bye")) break;
StringTokenizer st = new StringTokenizer(line);
Vector v = new Vector();
while (st.hasMoreTokens()) {
String token = st.nextToken();
v.addElement(token);
}
System.out.println("Vector: " + v);
boolean finished;
do {
finished = true;
System.out.println("Let's look at it, perhaps we're finished already...");
finished = finished && eliminateRedundantParens(v);
System.out.println("parens says done? " + finished);
// do the same with *'s
// finished = finished && reduceStars(v);
finished = reduceStars(v) && finished;
System.out.println("stars says done? " + finished);
// finished = finished && reducePluses(v);
finished = reducePluses(v) && finished;
System.out.println("pluses says done? " + finished);
} while (! finished);
System.out.println("After processing: " + v);
}
System.out.println("Thanks, come back!");
} // main
static boolean eliminateRedundantParens(Vector v) {
boolean done = true;
for (int i = 1; i < v.size() - 1; i++) {
if (isNumber((String) v.elementAt(i)) &&
i >= 1 && v.elementAt(i-1).equals("(") &&
v.elementAt(i+1).equals(")")
) {
v.removeElementAt(i+1);
v.removeElementAt(i-1);
i -= 2;
done = false;
System.out.println("Ooops!... " + v);
}
}
return done;
} // eliminateRedundantParens
static boolean isNumber(String str) {
try {
int num = Integer.parseInt(str);
} catch (Exception e) {
return false;
}
return true;
} // isNumber
static boolean reducePluses(Vector v) {
boolean done = true;
for (int i = 1; i < v.size() - 1; i++) {
if (v.elementAt(i).equals("+") &&
isNumber((String)v.elementAt(i-1)) &&
isNumber((String)v.elementAt(i+1)) &&
! ( (i-2) >= 0 && v.elementAt(i-2).equals("*") ||
(i+2) < v.size() && v.elementAt(i+2).equals("*"))
) {
int sum = Integer.parseInt((String)v.elementAt(i-1)) +
Integer.parseInt((String)v.elementAt(i+1));
v.setElementAt(sum + "", i-1);
v.removeElementAt(i+1);
v.removeElementAt(i);
i -= 1;
done = false;
}
}
System.out.println("Pluses: " + v);
return done;
} // reducePluses
static boolean reduceStars(Vector v) {
boolean done = true;
for (int i = 1; i < v.size() - 1; i++) {
if (v.elementAt(i).equals("*") &&
isNumber((String)v.elementAt(i-1)) &&
isNumber((String)v.elementAt(i+1))
) {
int p = Integer.parseInt((String)v.elementAt(i-1)) *
Integer.parseInt((String)v.elementAt(i+1));
v.setElementAt(p + "", i-1);
v.removeElementAt(i+1);
v.removeElementAt(i);
i -= 1;
done = false;
}
}
System.out.println("Stars: " + v);
return done;
} // reducePluses
} // class Six
Sat Aug 3
Fri Aug 2
There
will be a help session on Sunday August 4, in LH102, from 6:30-8:30pm.
Thu Aug 1import java.util.*;
class Eval {
public static void main(String[] args) {
ConsoleReader c = new ConsoleReader(System.in);
do {
System.out.print("Eval>");
String line = c.readLine();
StringTokenizer st = new StringTokenizer(line);
Vector v = new Vector();
while (st.hasMoreTokens()) {
v.addElement(st.nextToken());
}
for (int i = 0; i < v.size(); i++)
System.out.print(v.elementAt(i) + " ");
System.out.println();
} while (true);
}
}
Wed Jul 31import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class One extends Applet implements MouseListener,
MouseMotionListener {
String where = "out";
public void init() {
addMouseListener(this); addMouseMotionListener(this);
}
public void paint(Graphics g) {
if (where.equals("in")) { System.out.println("No smile."); }
else { System.out.println("Broad smile."); }
}
public void mouseMoved(MouseEvent e) { System.out.println("A-ha!"); }
public void mouseDragged(MouseEvent e) { }
public void mouseClicked(MouseEvent e) { }
public void mousePressed(MouseEvent e) { }
public void mouseReleased(MouseEvent e) { }
public void mouseExited(MouseEvent e) {
where = "out";
repaint();
}
public void mouseEntered(MouseEvent e) {
where = "in";
repaint();
}
}
Lecture Notes Twenty-Eight (for next Monday) provide a comprehensive
review of inheritance (or, the Java class extension mechanism) concepts.
The notes are long, and they may seem highly specialized, so start
reading them now, and be patient: they give you the crux of the
subject matter, leaving nothing out for later (or never.)
Although all of the presented examples are new, many concepts have already been covered, and therefore large portions of these notes can be used as a review so relax, and enjoy.
Tue Jul 30/*
<applet code="Thirty.class" width=300 height=300>
</applet>
*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Thirty extends Applet implements MouseMotionListener,
MouseListener
{
int x0 = (int)(Math.random() * 200 + 50);
int y0 = (int)(Math.random() * 200 + 50);
int x1 = (int)(Math.random() * 200 + 50);
int y1 = (int)(Math.random() * 200 + 50);
public void paint(Graphics g) {
for (float t = 0; t <= 1; t = t + 0.05f ) {
int x = (int)(x0 + t * (x1 - x0));
int y = (int)(y0 + t * (y1 - y0));
int r = 5;
Color shade = new Color(0, 0.5f + t / 2, 0);
g.setColor(shade);
g.fillOval(x-r, y-r, 2 * r, 2 * r);
g.setColor(Color.black);
g.drawOval(x-r, y-r, 2 * r, 2 * r);
}
}
public void init() {
this.addMouseMotionListener(this);
this.addMouseListener(this);
}
public void mouseMoved(MouseEvent e) {
int x = e.getX(), y = e.getY();
}
public void mouseDragged(MouseEvent a) {
if (outside) { } else {
int x = a.getX(), y = a.getY();
x1 = x; y1 = y;
this.repaint();
}
}
public void mousePressed (MouseEvent a) {
x0 = a.getX();
y0 = a.getY();
System.out.println("Changed x0, y0");
}
boolean outside = true;
public void mouseReleased(MouseEvent a) { }
public void mouseClicked (MouseEvent a) { }
public void mouseEntered (MouseEvent a) {
outside = false;
System.out.println("Mouse is now inside...");
}
public void mouseExited (MouseEvent a) {
outside = true;
System.out.println("Mouse is now outside...");
}
}
Can you see what the modification was?
Mon Jul 29
Sun Jul 28
Sat Jul 27I will try to schedule one for next week, though.
Fri Jul 26
Practice_Nine, and
Practice_Ten
Thu Jul 25
What aboutAnswer: we can't access ax.hornifHorse x = new Unicorn();?
Unicorn's horn through a
Horse variable. This, however, is a very good point, which has two parts.
Horses and Unicorns together
(uniformly) in one
array.
Unicorn
variable (read set of binoculars) to(wards) the Unicorn
object.
We'll talk more about this aspect
when we start using Vectors to
store and retrieve objects.
Here's the code we wrote at the end of the class today:
/*
<applet code="One.class" width=400 height=400>
</applet>
*/
import java.applet.*;
import java.awt.*;
public class One extends Applet {
public void paint(Graphics g) {
g.drawOval(30, 30, 100, 100);
g.drawOval(130, 130, 100, 200);
g.drawOval(230, 230, 150, 100);
g.drawOval(80, 80, 50, 50);
}
}
Notice that with this approach you don't need a separate
.html file. Create One.java (the
source code) with the applet tag included as a comment, then
compile the source code (with javac) and run
appletviewer on it. Notes for next week posted.
I won't be able to come to labs today, so you will be with Messrs. Li and Li (as you would, usually, on Mondays). I will return to labs next Thursday. If you need me in any way please let me know by e-mail or in class, or make an appointment, or come to any of my office hours.
Lab notes for today (including lab assignment) posted.
Wed Jul 24Notes updated a little bit for today and yesterday (some shifting happened).
Tue Jul 23First, the recursive bubble sort (with justification):
class One {
public static void main(String[] args) {
boolean done = true;
for (int i = 0; i < args.length - 1; i++) {
if (Integer.parseInt(args[i]) > Integer.parseInt(args[i+1])) {
done = false;
String temp = args[i];
args[i] = args[i+1];
args[i+1] = temp;
}
}
if (done) {
System.out.print("Here's the array sorted: ");
for (int i = 0; i < args.length; i++)
System.out.print(args[i] + " ");
System.out.println();
} else {
One.main(args);
}
}
}
Then, the debugging example that was our starting point on the homework:
class Two {
public static void main(String[] args) {
String one = args[0], two = args[1];
int max = Math.max(one.length(), two.length());
System.out.println(max);
for (int i = 1, diff = max - one.length(); i <= diff; i++) {
System.out.println("Adding zero no. " + i);
one = "0" + one;
}
for (int i = 0; i < max - two.length(); i++) {
two = "0" + two;
}
System.out.println(" " + one + " + ");
System.out.println(" " + two + " ");
for (int i = 0; i < max + 3; i++) System.out.print("-");
System.out.println();
}
}
Sun Jul 21
Sat Jul 20
Fri Jul 19All remaining homework assignments have been posted now.
Code used to produce sample output for third homework posted also, with question.
Thu Jul 18class One {
public static void main(String[] args) {
int[] a = One.generate(10, 0, 100);
double avg = One.average(a);
One.show(a);
System.out.println("Average is: " + avg);
}
static int[] generate(int size, int low, int hi) {
int[] temp = new int[size];
for (int i =0; i < size; i++)
temp[i] = One.value(low, hi);
return temp;
}
static int value(int low, int hi) {
return (int)(Math.random() * (hi - low) + low);
}
static void show(int[] a) {
for (int i = 0; i < a.length; i++)
System.out.print(a[i] + " ");
System.out.println();
}
static double average(int[] x) {
double sum = 0;
for (int i = 0; i < x.length; i++)
sum += x[i];
return sum / x.length;
}
}
Wed Jul 17class Wednesday {
public static void main(String[] args) {
int[] a = { 5, 2, 3, 1, 6, 3, 4, 5, 1};
Wednesday.show(a);
Wednesday.sort(a);
Wednesday.show(a);
}
static void show(int[] b) {
for (int i = 0; i < b.length; i++) {
System.out.print(b[i] + " ");
}
System.out.println();
}
static void sort(int[] b) {
for (int i = 0; i < b.length; i++) {
for (int j = i; j < b.length; j++) {
if (b[j] < b[i]) {
int temp = b[i];
b[i] = b[j];
b[j] = temp;
}
}
}
}
}
And here's the first program:
frilled.cs.indiana.edu%cat Arguments.java
class Arguments {
public static void main(String[] args) {
System.out.println("------------------------Case 1---");
int a = 3;
System.out.println("Before: " + a);
Arguments.fun(a);
System.out.println("After: " + a);
System.out.println("------------------------Case 2---");
int[] b = { 3, 1, 2, 4};
System.out.println("Before: " + b[0]);
Arguments.fun(b);
System.out.println("After: " + b[0]);
}
static void fun(int n) {
n += 1;
}
static void fun(int[] n) {
n[0] += 1;
}
}
[2] - Done emacs Arguments.java
frilled.cs.indiana.edu%javac Arguments.java
frilled.cs.indiana.edu%java Arguments
------------------------Case 1---
Before: 3
After: 3
------------------------Case 2---
Before: 3
After: 4
frilled.cs.indiana.edu%
Tue Jul 16class Max {
public static void main(String[] args) {
ConsoleReader console = new ConsoleReader(System.in);
System.out.print("What size: ");
int size = console.readInt();
int[] a = new int[size];
for (int i = 0; i < size; i++)
a[i] = (int)(Math.random() * 50);
System.out.print("Here's the array: ");
for (int i = 0; i < size; i++)
System.out.print(a[i] + " ");
int max = a[0];
for (int i = 0; i < size; i++)
if (a[i] > max)
max = a[i];
System.out.println("The max number is: " + max);
}
}
And here's the first program:
import java.util.*;
class Backwards {
public static void main(String[] args) {
ConsoleReader console = new ConsoleReader(System.in);
System.out.print("Type a line: ");
String line = console.readLine();
StringTokenizer stack = new StringTokenizer(line);
String result = "";
while (stack.hasMoreTokens()) {
String t = stack.nextToken();
result = // result + " " + t;
t + " " + result;
}
System.out.println(result);
}
}
Sun Jul 14
class Triangle {
// Point a, b, c;
double ab, ac, bc;
// storing the squares of the sides here would solve the precision problem
Triangle(Point a, Point b, Point c) {
// this.a = a; this.b = b; this.c = c;
ab = a.distanceTo(b);
ac = a.distanceTo(c);
bc = b.distanceTo(c);
}
boolean isRight() {
return (ab * ab == bc * bc + ac * ac) ||
// see lecture notes 6 and book chapter 5 for how we compare
// floating-point numbers for equality (section 5.2.2, pp. 190-191)
(ac * ac == bc * bc + ab * ab) ||
(bc * bc == ab * ab + ac * ac);
}
boolean isScalene() {
return (ab != ac && ab != bc && bc != ac);
// return ! this.isIsosceles();
}
boolean isIsosceles() {
return (ab == ac || ab == bc || bc == ac);
}
boolean isEquilateral() {
// if (ab == bc && bc == ac) return true; else return false;
return (ab == bc && bc == ac);
}
public String toString() {
return "Triangle w/ sides: (" + ab + ", " + bc + ", " + ac + ")\n" +
ab * ab + " " + bc * bc + " " + ac * ac ;
}
public static void main(String[] args) {
System.out.println("Hello!");
Triangle t1 = new Triangle( new Point(1, 0),
new Point(),
new Point(0, 3) );
System.out.println(t1);
System.out.println("Is it a right triangle? Answer: " + t1.isRight());
System.out.println("Is it a scalene triangle? Answer: " +
t1.isScalene());
System.out.println("Is it a isosceles triangle? Answer: " +
t1.isIsosceles());
System.out.println("Is it a equilateral triangle? Answer: " +
t1.isEquilateral());
System.out.println(2 + " == " + Math.sqrt(2) * Math.sqrt(2));
java.awt.Rectangle r = new java.awt.Rectangle(2, 2, 10, 20);
System.out.println(r);
}
}
class Point { // from the Dilbert lecture
double x, y;
Point() {
x = 0;
y = 0;
}
Point(int initialX, int initialY) {
x = initialX;
y = initialY;
}
void report() {
System.out.println("Point at: (" + x + ", " + y +")");
}
double distanceTo (Point other) {
double temp;
temp = (x - other.x) * (x - other.x) +
(y - other.y) * (y - other.y);
return Math.sqrt(temp);
}
}
Here's a link to the Emacs installation tutorial. There's a help session tonight (Sun) in LH102 at 6:30pm.
Understanding
(both very well) is fundamental for your good performance on the Practical Exam.
Sat Jul 13
Grades for the midterm exam, minute paper statistics,
posted.
Thu Jul 11
Extra office hour tonight 8:30-9:30pm in LH016.
Wed Jul 10Notes for the rest of the week posted.
Tue Jul 9Here's an example of a problem that you might get on the practical exam:
Sample Practical Problem. Write a class called
Triangle that can be used to represent a triangle. It
should include the following methods that return boolean
values indicating if the particular property holds:
isRight (a right triangle)
isScalene (no two sides are the same length)
isIsosceles (exactly two sides are the same length)
isEquilateral (all three sides are the same length)
Write a simple tester program that creates a few triangles and asks them about their type.
Homework Three posted.
Two more batches of exercises have been posted in QuizSite.
Exam on Friday (1:30pm in LH102) is multiple-choice, similar to the QuizSite exercises.
Lecture notes for today have been posted.
Mon Jul 8
Sun Jul 7
Help Session Today (SUNDAY,
July 7) in LH102 (6:30pm-8:30pm).
Sat Jul 6
Warmups: Chapter
Two Review Exercises
(http://www.cs.indiana.edu/classes/a201-dger/sum2002/notes/chapTwoReview.html)
Solutions for
Chapter Two Warmups
(http://www.cs.indiana.edu/classes/a201-dger/sum2002/notes/chapTwoRevSols.html)
Programming Problems:
Chapter Two Programming Exercises
(http://www.cs.indiana.edu/classes/a201-dger/sum2002/notes/chapTwoProbs.html)
Solutions for
Chapter Two Programming Exercises
(http://www.cs.indiana.edu/classes/a201-dger/sum2002/notes/chTwoPSols.html)
Warmups: Chapter
Three Review Exercises
(http://www.cs.indiana.edu/classes/a201-dger/sum2002/notes/w2.html)
Solutions for
Chapter Three Warmups
(http://www.cs.indiana.edu/classes/a201-dger/sum2002/notes/w2Sol.html)
Programming Problems:
Chapter Three Programming Exercises
(http://www.cs.indiana.edu/classes/a201-dger/sum2002/notes/set2.html)
Modeling with Diagrams.
(http://www.cs.indiana.edu/classes/a201-dger/sum2002/notes/rodS.html)
Solutions for
Chapter Three Programming Exercises
(http://www.cs.indiana.edu/classes/a201-dger/sum2002/notes/set2Sol.html)
Warmups: Chapter
Five Review Exercises
(http://www.cs.indiana.edu/classes/a201-dger/sum2002/notes/ifs.html)
Solutions for
Chapter Five Warmups
(http://www.cs.indiana.edu/classes/a201-dger/sum2002/notes/ifsSol.html)
Programming Problems:
Chapter Five Programming Exercises
(http://www.cs.indiana.edu/classes/a201-dger/sum2002/notes/pIfs.html)
Solutions for
Chapter Five Programming Exercises
(http://www.cs.indiana.edu/classes/a201-dger/sum2002/notes/pIfsSol.html)
Sat Jun 29Please note that Lab Five this week is due in two stages.
Thu Jun 27
Tue Jun 25
Finally
QuizSite has been initialized. Note however the name of the class I registered
the combined rosters under is J201.
Please try logging in and let me know if you can't get in to submit
the first homework assignment. An example of a plan of action involving decisions and decision-making.
Mon Jun 24
Sun Jun 23
Thu Jun 20I only need to initialize QuizSite now, with this semester's roster.
Here's the code we developed in class today:
class Two {
public static void main(String[] args) {
ConsoleReader console;
console = new ConsoleReader(System.in);
System.out.println("Hello, what's your name?");
String name = console.readLine();
System.out.println("Hello " + name + " enter a temperature in " +
" degrees Fahrenheit.");
double fahrenheit = console.readDouble();
System.out.println( (fahrenheit - 32 ) * 5 / 9 );
}
}
Wed Jun 19Please note a small change in my office hours time on Thursdays, below.
Today in class we will talk about
Also we'll review and clarify the numbering used in Lab One for the tiles in the Rink.
Tue Jun 18
And with a big help of our friend the Penguin we will be looking at
Our Penguin's name (by the way) is Pixel Pete.
(The Aardman's penguin's name is Feathers, apparently).
Our office hours:
| Instructor | Username | Days | Location | Time |
|---|---|---|---|---|
| Adrian German | dgerman | MTWF | LH201D |
3-4pm |
| Thursday(only) | LH201D | 12:25-1:25pm | ||
| Richard Li | yli | TW | LH016 (basement, Lindley) | 5:30-6:30pm |
| Barry Li | yinli | MR | LH016 (basement, Lindley) | 2:30-3:30pm |
Mon Jun 17