A201 Web-based Bulletin Board

Second Summer 2003


Wed Aug 20
End of semester. Here's a poem by Nichita Stanescu to wish you good bye as we disappear slowly into the last few days of golden summer sunlight. Congratulations to you for your hard work, and all best wishes, my dear friends. It was hard work, no question about it---but I know that you will do well.

Adolescents on the sea

This sea is covered with adolescents
learning to walk on waves, upright,
sometimes resting their arms on the currents,
sometimes gripping a stiff beam of sunlight.

I lie on the broad beach, an angled shape, cut perfectly,
and I ponder them like travelers landing.

An infinite fleet of yawls. I wait to see
a false step, or at least a grounding
up to knee in the diaphanous swell
beneath their measured progress, sounding.

But they are slim and calm - as well,
they've learned to walk on waves - and standing.

On behalf of Sriram and Richard, I salute you.

... Adrian

Mon Aug 18
Final Grades posted just now.

Sun Aug 17
Practical Exams impressive, as expected.

Sat Aug 16
I am reading your tutorials. Imagine for a moment that I will be giving them to the A201 students that will take this class in a future semester in an attempt to get them started on these projects. Will they find your tutorials helpful? Will they appreciate the insight? How would your tutorials do, when meeting face to face with your colleagues? You are looking them in the eye from the tutorials, aren't you? Some tutorials are extremely good, I must say.

Fri Aug 15
Raw scores for the Final Exam have been posted now.

I am grading. But it's a very time consuming and extremely slow process. I am putting together the key to the final exam. Once that is ready (whenever that might be, since I only started Friday at noon) I will have the test scanned and the resulting grades entered into the gradebook. You are more than welcome to write to me about any kind of question that you might have. I am very serious: e-mail is always welcome, whatever the reason for it. It might take a while for me to respond (especially today), but I enjoy it all with no exceptions. So, grading is under way.

Thu Aug 14
Final Exam today continues in lab (optional).

Final Exam today in class at 1:30pm, multiple-choice.

Bring your own No. 2 pencil.

Wed Aug 13
Final Exam tomorrow, in class.

Copies of batches of exercises in QuizSite.

Tue Aug 12
Date: Tue, 12 Aug 2003 07:38:08 -0500 (EST)
From: Adrian German <dgerman@cs.indiana.edu>
To: A201 Summer 2003 Distr. List <dgerman@indiana.edu>
Cc: Adrian German <dgerman@cs.indiana.edu>
Subject: Lecture Today (Homework Help) 


Part of your success on the homework assignment is knowing
what to pick. Today in class I will illustrate the process
of choosing the right project(s) and writing a tutorial for
it (them). Bring your books. I will be doing Homework Four and
Five myself, in front of a live(ly) studio audience. See you in
class. I can hardly wait. How about you?

... Adrian
Bring your book(s) to class from now on (today and tomorrow).

Homework Four is due Wed and Five is due Thu.

There is a Help Session on Wed night (the last one) at 7pm in LH102.

Mon Aug 11
Due date for Homework Four pushed to Wednesday.

The Quotation below translated: "When in trouble ask for help."

Or, put it another way: "Come to (every) class. You never know when something truly useful might be presented." Homework One and Midterm Reviews have been graded and will be returned to you in Labs today.

Here's the Quotation for this last week of Summer II 2003:

We are each an angel with only one wing.
And we can only fly while embracing each other.

Luciano De Crescenzo

Sun Aug 10
Here are two minute papers of Thursday.

Minute Paper One:

I believe that the best way that I have learned in this class is by you constructing a program in front of us on the computer, to see you creating the code, seeing you fix errors, and you explaining along the way. I also enjoy when you are creating the program to ask us the next step, or for us to solve it first and then you will show us the answer after we have a chance to think through it first.

I do not like, so much, when you go from the quiz site or class notes. We are just looking at code posted and then another set of code and so on. It gets rather uninteresting. I hope this isn't rude or in some way discouraging. I just feel like I could have done this at home and to ask you questions that I have. The hands on approach. Instead of you just going down the page and showing the same code changed a little bit, like I said I could do that at home.

Just some thoughts from lecture today.
Minute Paper Two:
Thank you for going over quiz site. It helps to see the way the questions were working.
Many thanks for both perspectives.

Another one was very funny, it just said: "Howdy!"

(It was written with a French accent, though.)

Finally I posted this to the e-mail distribution list on Fri night:

Date: Fri, 8 Aug 2003 21:01:42 -0500 (EST)
From: Adrian German <dgerman@cs.indiana.edu>
To: A201 Summer 2003 Distr. List <dgerman@indiana.edu>
Subject: A201/I210/A597 Update


I have received some questions about Homework Four and Five on
Wednesday night and then Thu in another minute paper and two more
by e-mail today so I would like to do two things in this message,
namely:

a) summarize the question(s) received, and

b) send the answers to everybody since there may be other students
wondering about the same thing.

The question basically was (my wording):

   "I don't know what you want from me. You want me to pick two
    projects. I can do that. You then say I should write a tutorial
    on how the program was designed and/or how it works. I don't know
    how to write a tutorial. Can you help me with that? Well, perhaps
    by tutorial you mean that I have to show my understanding of how
    the program was designed and/or how it works. But I don't know how
    to show my understanding about the program. (Sorry.) Can you help?
    Finally, is there an ideal homework example posted? If so, then
    what is the URL?"

Many thanks for the questions. Below is my answer:

    If you choose the               the best example of a tutorial
                                    for it is in the book in Chapter

    TechSupport project                    5
    Bouncing Balls project                 5
    Calculator project                     6
    World of Zuul project                  7
    DoME project                           8-9
    Rabbits and Foxes project              10
    Taxi Simulation                        13 (12 is useful reading)

Hope this helps.

Next week is entirely dedicated to helping you finish Homework Four
and Five. Labs and lectures will only focus on that and on making sure
you're ready for the Final as well. The Final is open book and open notes.
There is a chance for the due date of Homework Four to be pushed a day or
two beyond the current due date, but we will have to wait for Monday to
make a decision on that. Hope you're doing well. Enjoy the weekend and
please let me know if you need any help. Yes, I am still working on the
grades. I think I am addicted to it by now. I can't seem to stop.

... Adrian

Sat Aug 9
Let's use the Bulletin Board to exchange thoughts on the last two assignments.

Fri Aug 8
Perhaps I will post some guiding questions about Homework Four and Five.

Perhaps I won't have the time. Meanwhile here are some pointers:

1. The TechSupport application is described in the book in pp. 105-135.

2. The Bounce application is in the book on pp. 135-141.

(I think I will post some guiding questions. This will help with grading).

3, 4. The extra projects Alien Landing and IceBlox are not explained in the book.

5. The Calculator is described in Chapter 6 (pp. 143-168).

6. The World-of-Zuul game is described in Chapter 7 (pp. 170-201).

7. The Database of Multimedia Entertainment is discussed on pp. 206-253.

Please all three versions and the differences between them.

8. The Simulation is described on pp. 255-286.

You will have to explain the design choices that take us to the last stage.

Chapter 11 is important, but we don't make a project out of it.

9. The Taxi Company project is the perfect case-study.

In analyzing it you might also benefit from reading Chapter 12.

The project is described on pp. 342-360.

I hope you enjoy these projects.

Thu Aug 7
Here's the final exam from Spring 2003.

Here are other two projects that you can choose as your Homework Four/Five:

A basic tutorial on what's going on in the programs is what is needed.

Wed Aug 6
Here's the code developed in class today:
/*  
 <applet code="One.class" 
         width=400 height=400>
 </applet>
 */ 

import java.applet.*;
import java.awt.*; 
import java.awt.event.*; 

public class One extends Applet {
  int x0 = 0, y0= 0, x1 = 150, y1 = 250;
  public void init() { 
    Broker a = new Broker(this); 
    this.addMouseMotionListener(a); 
  }
  public void paint(Graphics g) {
    this.drawLine(x0, y0, x1, y1, g); 
  }
  void drawLine(int x0, int y0, int x1, int y1, Graphics g) {
    for (double t = 0; t < 1; t += 0.05) {
      int x = (int) (x0 + t * (x1 - x0)); 
      int y = (int) (y0 + t * (y1 - y0)); 
      g.fillOval(x, y, 10, 10); 
    }
  }
}

class Broker implements MouseMotionListener {
  One client; 
  Broker(One client) { this.client = client; }   
  public void mouseMoved(MouseEvent e) { 
    client.x1 = e.getX(); 
    client.y1 = e.getY(); 
    client.repaint(); 
  }
  public void mouseDragged(MouseEvent e) { 
    System.out.println("Mouse dragged..."); 
  }
}
There will definitely be a help session this Wed at 7pm.

Some more help with Lab Eleven:

import java.applet.*; 
import java.awt.*;
import java.awt.event.*;

/*  
  <applet code=One.class width=300 height=300></applet>
*/ 

public class One extends Applet implements MouseListener, 
                                           MouseMotionListener {
  public void init() { 
    e1 = new Eye();
    e2 = new Eye(); 
    n = new Nose(); 
    m = new Mouth();  
    this.addMouseListener(this); 
    this.addMouseMotionListener(this); 
  }
  public void paint(Graphics g) {
    e1.draw(g); 
    e2.draw(g); 
    n.draw(g); 
    m.draw(g, out); 
    System.out.println("paint has finished...");
  } 
  public void mouseDragged(MouseEvent e) { }
  public void mouseMoved(MouseEvent e) { 
    out = false;     
                
  }

  boolean out = true; 

  Eye e1, e2; 
  Nose n; 
  Mouth m;
  public void mousePressed(MouseEvent e) { }
  public void mouseReleased(MouseEvent e) { }
  public void mouseClicked(MouseEvent e) { }
  public void mouseExited(MouseEvent e) { 
    out = true;
    System.out.println("Out...");  
    repaint();
  }
  public void mouseEntered(MouseEvent e) { 
    out = false; 
    System.out.println("Back in!");  
    repaint(); 
  }

}

class Eye { 
  public void draw(Graphics g) { } 
}
class Nose { 
  public void draw(Graphics g) { } 
} 
class Mouth { 
  int x, y, width = 300, height = 150, start = 190, stop = 160; 
  public void draw(Graphics g, boolean out) { 
    if (out/* == true*/) {
      System.out.println("Broad smile."); 
      g.drawArc(x, y, width, height, start, stop);  
    } else { 
      System.out.println("Attentive smile..."); 
      g.drawArc(x, y, width, height, start + 40, stop - 2 * 40); 
    } 

  } 
}

Tue Aug 5
Here's the code developed at the end of the lecture today.

/* 
 <applet code="One.class" width=100 
                          height=100>
 </applet>
 */ 

import java.applet.*; 
import java.awt.event.*; 

public class One extends Applet {

  public void init() {
    this.addMouseMotionListener(new Umpire()); // bring the umpire to the game
  }
  
}

class Umpire implements MouseMotionListener { // umpire must wear uniform 
  public void mouseMoved(MouseEvent e) {  // uniform has two sleeves umpire must fill
    System.out.println("Mouse moved...");
  }
  public void mouseDragged(MouseEvent e) { // here's providing the second one 
    System.out.println("Mouse being dragged at (" + 
                       e.getX() + ", " + e.getY() + ")"); 
  }
}
Here's the link to the notes on double buffering that we discussed yesterday.

Mon Aug 4
Here's the code developed in class today:
/* <applet code=One.class width=600 height=600>

   </applet>
 */ 

import java.applet.*; 
import java.awt.*; 
import java.awt.event.*; 

public class One extends NoFlickerApplet 
                 implements MouseMotionListener,
                            MouseListener {

  Circle[] circles; // array instance variable declared

  public void init() {
    circles = new Circle[400]; // allocate 
    for (int i = 0; i < circles.length; i++) { // initialize
      circles[i] = new Circle(

        (int)(Math.random() * 600), // x 
        (int)(Math.random() * 600), // y 
        (int)(Math.random() * 40 + 10), // r
        new Color((float) Math.random(), 
                  (float) Math.random(), 
                  (float) Math.random())
       ); 
       this.addMouseMotionListener(this);       
       this.addMouseListener(this);       

    }
   
  }

  public void paint(Graphics g) {
    for (int i = 0; i < circles.length; i++)
      circles[i].draw(g); 
  }

  Circle selectedCircle; 

  public void mousePressed(MouseEvent e) { 
    int x = e.getX(), y = e.getY(); 
    for (int i = 0; i < circles.length; i++) {
      if (circles[i].contains(x, y)) {
        selectedCircle = circles[i]; 
        /* return; */ 
      }
    }
  }

  public void mouseDragged(MouseEvent e) { 
    int x = e.getX(), y = e.getY(); 
    if (selectedCircle != null) {
      selectedCircle.move(x, y); 
      repaint();        
    } 
  }
  public void mouseReleased(MouseEvent e) { 
    selectedCircle = null; 
  }

  public void mouseMoved(MouseEvent e) { }
  public void mouseEntered(MouseEvent e) { }
  public void mouseExited(MouseEvent e) { }
  public void mouseClicked(MouseEvent e) { }

}

class Circle { 
  int x, y, radius;
  Color c; 
  Circle(int x, int y, int r, Color c) {
    this.x = x; this.y = y; this.radius = r; this.c = c; 
  }
  void draw(Graphics g) {
    g.setColor(this.c); 
    g.fillOval(this.x, this.y, this.radius * 2, this.radius * 2);
    g.setColor(Color.black); 
    g.drawOval(this.x, this.y, this.radius * 2, this.radius * 2); 
   
  }
  boolean contains(int x, int y) {
    int xC = this.x + this.radius; 
    int yC = this.y + this.radius; 
    double distance = Math.sqrt((xC - x) * (xC - x) + 
                                (yC - y) * (yC - y)); 
    return distance <= radius; 
  }
  void move(int x, int y) {
    this.x = x - this.radius; this.y = y - this.radius; 
  }
}
In preparation for the Final Exam QuizSite has four new batches of exercises.

Please check them out. (They're the last.)

Fri-Sun Aug 1-3
What's Due? page has been updated.

For Homework Four and Five please refer to this document.

Thu Jul 31
Here's the code we developed in class today:
/* <applet code=One.class width=600 height=600>

   </applet>
 */ 

import java.applet.*; 
import java.awt.*; 
import java.awt.event.*; 

public class One extends Applet 
                 implements MouseMotionListener {

  Circle[] circles; // array instance variable declared

  public void init() {
    circles = new Circle[100]; // allocate 
    for (int i = 0; i < circles.length; i++) { // initialize
      circles[i] = new Circle(

        (int)(Math.random() * 600), // x 
        (int)(Math.random() * 600), // y 
        (int)(Math.random() * 40 + 10), // r
        new Color((float) Math.random(), 
                  (float) Math.random(), 
                  (float) Math.random())
       ); 
       this.addMouseMotionListener(this);       
    }
   
  }

  public void paint(Graphics g) {
    for (int i = 0; i < circles.length; i++)
      circles[i].draw(g); 
  }

  public void mouseDragged(MouseEvent e) {
    System.out.println("Mouse dragged at (" + 
      e.getX() + ", " + e.getY() + ")"
    ); 
  }

  public void mouseMoved(MouseEvent e) {
    System.out.println("Mouse moved at (" + 
      e.getX() + ", " + e.getY() + ")"); 
  }

}

class Circle { 
  int x, y, radius;
  Color c; 
  Circle(int x, int y, int r, Color c) {
    this.x = x; this.y = y; this.radius = r; this.c = c; 
  }
  void draw(Graphics g) {
    g.setColor(this.c); 
    g.fillOval(this.x, this.y, this.radius * 2, this.radius * 2);
    g.setColor(Color.black); 
    g.drawOval(this.x, this.y, this.radius * 2, this.radius * 2);
    
  }

}
Applets, Vectors, event handling today.

Even double-buffering if we have time.

Wed Jul 30
I am not going to be able to offer the help session tonight (7/30).

Tue Jul 29
Here's the code from yesterday:
class Point {

  private double x, y;

  double x() { return x; } 

  double y() { return y; } 

  Point(double x, double y) {
    this.x = x; 
    this.y = y;
  }

  public String toString() {
    return "I am a Point at (" + x + ", " + y + ")"; 
  }
} 

class Circle {

  private double radius, x, y; 

  Circle(double r, double x, double y) {
    radius = r; 
    this.x = x; 
    this.y = y; 
  }

  Point center() {
    return new Point(this.x, this.y); 
  }

  double radius() {
    return radius; 
  }

} 

class Rectangle {

  double x, y, width, height; 

  Rectangle(double x, double y, double width, double height) {
    this.x = x; 
    this.y = y;
    this.width = width;
    this.height = height; 
  }

} 

class LabEight { 
  public static void main(String[] args) {
      for (int i = 0; i < 10; i++) 
          System.out.println(LabEight.random(-14, -8)); 

      for (int i = 0; i < 10; i++) 
          System.out.println(LabEight.random(3.2, 3.9));  
      Point p1 = new Point(1, 4); 
      Point p2 = new Point(5, 1); 
      System.out.println(LabEight.distance(p1, p2)); 
      Point p3 = LabEight.midpoint(p1, p2); 
      System.out.println(p3.toString()); 
      Circle c1 = new Circle(10, 3,  3); 
      Circle c2 = new Circle( 9, 3, 21); 
      System.out.println(
          "Circles overlap? The answer is: " + 
          LabEight.overlaps(c1, c2));
      Rectangle r1 = new Rectangle(5, 5, 5, 5);  
      Rectangle r2 = new Rectangle(7, 1, 2, 2);
      System.out.println(
          "Rectangles overlap? The answer is: " + 
          LabEight.overlaps(r1, r2)); 
  }

  static int random(int high, int low) {
    return (high + low) / 2; 
  } 

  static double random(double high, double low) {
    return high - low; 
  }

  static double distance(Point a, Point b) {
    return 2.3; 
  }

  static Point midpoint(Point a, Point b) {
    return new Point(12, 8); 
  }

  static boolean overlaps(Circle a, Circle b) {
    return false; 
  }

  static boolean overlaps(Rectangle a, Rectangle b) {
    return true; 
  }

}

Mon Jul 28
Checking if Rectangles overlap thanks to Lance Watanabe:

Rectangle second, first;
Second to be South of the first:
second.y >= first.y + first.h
Second to be North of the first:
second.y + second.h <= first.y
Second to be East of the first:
second.x >= first.x + first.w
Second to be West of the first:
second.x + second.w <= first.x
East or West or South or North means: Outside.

Overlaps is NOT Outside.

Here's the initial shape of Lab Eight as developed in class today:

(Apparently the code was lost).

Sat-Sun Jul 26-27
URL for the Practical Exam.

Fri Jul 25
Remember the Practical has two parts:

  1. 40% for what you turn in in class on Thu night and
  2. 60% for what you turn in to QuizSite (before Mon 23:59)

QuizSite was opened at 3pm on Thu.

Thu Jul 24
Here's the output for the code developed in class:
frilled.cs.indiana.edu%javac Example.java
frilled.cs.indiana.edu%java Example
100> Your turn.
20 marbles removed. (80)
80> Computer's turn.
50 is not a legal move.
80> Computer's turn.
-4 is not a legal move.
80> Computer's turn.
5 marbles removed. (75)
75> Your turn.
17 marbles removed. (58)
58> Computer's turn.
8 marbles removed. (50)
50> Your turn.
25 marbles removed. (25)
25> Computer's turn.
12 marbles removed. (13)
13> Your turn.
6 marbles removed. (7)
7> Computer's turn.
3 marbles removed. (4)
4> Your turn.
2 marbles removed. (2)
2> Computer's turn.
1 marbles removed. (1)
1> Your turn.
1 marbles removed. (0)
You have lost.
New game started.
100> Your turn.
1 marbles removed. (99)
99> Computer's turn.
1 marbles removed. (98)
98> Your turn.
1 marbles removed. (97)
97> Computer's turn.
1 marbles removed. (96)
96> Your turn.
1 marbles removed. (95)
95> Computer's turn.
1 marbles removed. (94)
94> Your turn.
1 marbles removed. (93)
frilled.cs.indiana.edu%
Compare this with an annotated version of the main below:
class Example {
  public static void main(String[] args) {
    GameBoy a = new GameBoy(); 
    a.withdraw(20); // me                 (100 becomes 80)  
    a.withdraw(50); // computer           (still 80)
    a.withdraw(-4); // computer           (still 80)
    a.withdraw(5);  // computer           (80 becoming 75)
    a.withdraw(17); // me                 (75 into 58) 
    a.withdraw(8);  //                    (58-8 is 50)
    a.withdraw(25); // me                 (25 remaining)
    a.withdraw(12); //                    (13 left)
    a.withdraw(6);  // me                 (only 7 now)
    a.withdraw(3);  //                    (4 more)
    a.withdraw(2);  // me                 (2 currently)
    a.withdraw(1);  // computer           (only one left)
    a.withdraw(1);  // me. I lose.        (I take it).
    a.withdraw(1);  // new game. Me again.(100-1 makes the pile 99 marbles high).
    a.withdraw(1);  // computer 
    a.withdraw(1);  // ... and so on
    a.withdraw(1); 
    a.withdraw(1); 
    a.withdraw(1); 
    a.withdraw(1); 
  }
}
Here's the program developed in class today (sample exam):
class Example {
  public static void main(String[] args) {
    GameBoy a = new GameBoy(); 
    a.withdraw(20); 
    a.withdraw(50); 
    a.withdraw(-4); 
    a.withdraw(5); 
    a.withdraw(17); 
    a.withdraw(8); 
    a.withdraw(25); 
    a.withdraw(12); 
    a.withdraw(6); 
    a.withdraw(3); 
    a.withdraw(2); 
    a.withdraw(1); 
    a.withdraw(1); 
    a.withdraw(1); 
    a.withdraw(1); 
    a.withdraw(1); 
    a.withdraw(1); 
    a.withdraw(1); 
    a.withdraw(1); 
    a.withdraw(1); 
  }
}

class GameBoy {
  int balance = 100; 
  void withdraw(int amount) {
    this.report(); 
    if ((amount <= this.balance / 2 && amount > 0) ||
        amount == 1) {
      this.balance = this.balance - amount;
      System.out.println(amount + 
                         " marbles removed. (" + 
                         this.balance + ")"); 
      if (this.balance == 0) {
        if (this.who == 0) System.out.print("You have "); 
        else System.out.print("The computer has "); 
        System.out.println("lost."); 
        System.out.println("New game started."); 
        this.balance = 100; 
        this.who = 0; 
      } else { 
        this.who = (this.who + 1) % 2; 
      } 
    } else {
      System.out.println(amount + " is not a legal move."); 
    }
  }
  int who = 0; // 0 is the user, 1 is the computer 
  void report() {
    System.out.print(this.balance + "> "); 
    if (who == 0) System.out.println("Your turn."); 
    else System.out.println("Computer's turn."); 
  }
}
Here's the code developed by Peter Cheun last night during the help session:
class Tigger {
  int count; // jumps per tigger (good idea of Lance Watanabe)
  String x, y;
  Tigger(int x, int y) {
    this.x = "" + x;
    this.y = "" + y;
  }
  void jump() {
    int x = Integer.parseInt(this.x);
    if(x % 2 == 0) x = x / 2;
    else x = 3 * x + 1;
    this.x = "" + x;
    int y = Integer.parseInt(this.y);
    if(y % 2 == 0) y = y / 2;
    else y = 3 * y + 1;
    this.y = "" + y;
    this.count += 1; // keep track of jumps 
    System.out.println(this.report());
  }

  String report() {
    return "Tigger is at jump " + this.count + 
           " and location (" + this.x + ", " + this.y + ").";
  }

}

class Exp {
  public static void main(String[] args) {
    Tigger a = new Tigger(27, 1023);
    while(!a.x.equals("1") && !a.y.equals("1"))
      a.jump();
    
  }
}

Wed Jul 23
Here's the SlotMachine exercise:
public class SlotMachine { 
  private int balance; 
  SlotMachine(int initialAmount) {
    this.balance = initialAmount;    
  }
  int getBalance() {
    return this.balance;
  }
  private void draw() {
    this.balance += 30; 

    long a, b, c; 

    a = Math.round(Math.random() * (14 - 1) + 1); 
    b = Math.round(Math.random() * (14 - 1) + 1); 
    c = Math.round(Math.random() * (14 - 1) + 1); 

    long sum = a + b + c; 

    System.out.println("You won: " + sum); 

    this.balance -= sum; 

    System.out.println("Machine currently has: " + 
                       this.getBalance()); 

  }
  int smallBalance; 
  void deposit(int amount) {
    this.smallBalance += amount;  
    if (this.smallBalance > 30) {
      System.out.println("Your change: " + 
                         (this.smallBalance - 30));
      this.draw(); 
      this.smallBalance = 0; 
    } else if (this.smallBalance == 30) {
             this.draw(); 
             this.smallBalance = 0; 
           } else {
             System.out.println("Your credit is: " + 
                                this.smallBalance); 
             System.out.println("I need " + 
                                (30 - this.smallBalance) +
                                " more."); 
           } 
  }
}

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

    SlotMachine a; 
    a = new SlotMachine(1000); 
    System.out.println(a.getBalance());

    a.deposit(30); 

    a.deposit(25); 
    a.deposit(5); 

    a.deposit(20); 
    a.deposit(8); 
    a.deposit(12); 

  }
}

Tue Jul 22
Don't forget the grades are posted in Postem/MyGrades:

Here's the code of yesterday:

class PacMan {
  static int nextId = 0; /* don't need to if zero... */ 
  int id;
  int h, m; 
  PacMan() { 
    this.id = PacMan.nextId; 
    PacMan.nextId += 1; 
  }
  PacMan(int pounds, int ounces) { 
    this(); 
    this.h = pounds; 
    this.h += ounces / 16; 
    this.m = ounces % 16;
  }
  PacMan(String weight) {
    this(Integer.parseInt(weight.substring(0,2)), 
         Integer.parseInt(weight.substring(3))); 
  }  
  String report() {
    String ounces = "00" + this.m; 
    String id = "000" + this.id; 
    id = id.substring(id.length() - 3); 
    return "PacMan with ID (" + id + ") currently weighs: " + 
           this.h + ":" + ounces.substring(ounces.length() - 2) ; 

  }
  void eatBagel() {
    System.out.println(this.report()); 
    System.out.println("I am getting ready to eat a bagel...");
    this.m += 1; 
    if (this.m >= 16) {
      this.h += this.m / 16;
      this.m = this.m % 16; 
    }
    System.out.println("I am done eating a bagel...");
    System.out.println(this.report() + "\n--------"); 
  }
  public static void main(String[] args) {
    PacMan a = new PacMan(); 
    System.out.println(a.report()); 
    PacMan b = new PacMan(14, 15); 
    System.out.println(b.report()); 
    PacMan c = new PacMan("19:17"); 
    System.out.println(c.report()); 
    System.out.println("How are you?"); 
    a.eatBagel(); 
    a.eatBagel(); 
    a.eatBagel(); 
    b.eatBagel(); 
  }
}

Mon Jul 21
The quote today is from Garrison Keillor:
"Some luck lies in not getting what you thought you wanted but getting what you have, which once you have got it you may be smart enough to see is what you would have wanted had you known."
Other than that the notes for next week have been sketched and we will be starting the week with two goals in mind:

Sun Jul 20
Chapter 3 in the BlueJ book can help intwo ways:

We'll discuss the exam exercises in class on Monday.

Here also is a partial list of students whose exams were impressive.

Kudos (i.e., congratulations and honors) are hereby being presented to:

... for their excellent performance on the exam on Thursday.

Also close to (and just barely short of) being impressive came the exams of:

I am sure the list(s) could be bigger. If your name is not listed don't worry: your time will come. This list is just a way to express sincere appreciation (as well as contented admiration on my part) for the most effective way that those listed above managed to handle the problems on the exam on Thursday. I am sure they could easily act as very good and effective peer tutors for what we've studied thus far. (There's an even bigger list of students whose potential seems to be just as significant, but for various reasons they got stuck in one part or the other of the exam and didn't quite make it on any of the two lists mentioned above. Next time for sure.)

Sat Jul 19
Here's the message sent yesterday to the distribution list:
Date: Fri, 18 Jul 2003 12:18:23 -0500 (EST)
From: Adrian German <dgerman@cs.indiana.edu>
To: A201 Summer 2003 Distribution List <dgerman@indiana.edu>
Subject: midterm grades


Dear A201/I210/A597 Friends,

I have graded a third of the papers and posted some
feedback already in Postem (section 4289). The rest
of the feedback will be posted by 3pm today. On Mon
(July 21) you will receive back your exams and will
have to finish/redo them on your own as a takehome.
When you're done (no strict deadline, but get to it
within the next two weeks) turn in a report to me -
for full credit.

This report should explain why the correct answers
come out the way they do (be very explicit) and also
should clearly identify the mistakes you made in the
exam, and how you fixed them when you reworked the
problems (and if you learned anything in the process).
I expect the reports to be complete, clear, and focused
on the specific mistakes you made on the exam, if any.

I will grade the reports and credit your exam grade
based on what I read in (and what I understand from)
your reports. So if you have feelings of depression and
thought the exam was hard the good news is that it's not
over -- you're still working on it, and when you have it
done you can get all the points w/ your perfect report.

Let me know if you need any help, and also if you have any
questions. Please don't forget there's a homework due Monday.
Next Wednesday we have our weekly help session. Hope everybody's
doing well. You may have thought that the exam was just a way of
putting you in a tight spot while also taking future opportunities
away from you, but it was not. Hard as it was, its purpose was to
give us a glimpse of the understanding that we've built in us thus
far, and now that we know how we stand on that, we need to patch it
and adjust it until it looks and acts reliably (the understanding,
that is). And that's what the takehome reports are for. You will be
grading your own exams, and in the process getting all the credit.

So I congratulate you all for your hard work. I have already seen a
couple of impressive exams, and am looking forward to grade them all
by 3pm as I said. I've been to labs yesterday and spoke to many of you.
The vast majority had already thought their exams over before I got to
speak to you in labs yesterday, and that was very refreshing.

Thank you once again and all the very best.

... Adrian

Fri Jul 18
Here's the exam of Thursday (answers included).

Help with Practice Three and Four posted (includes Homework Three help).

Thu Jul 17
BlueJ book on reserve has had the CD broken into pieces.

Instructor is very disappointed...

Here's the code we developed in class yesterday:

public class Math {
  public static int gcd(int n, int m) {
    int candidate = 1;
    int gcdThusFar = 1; 
    while (candidate <= java.lang.Math.min(n, m)) {
      if (n % candidate == 0 && m % candidate == 0) 
        gcdThusFar = candidate; 
      candidate = candidate + 1; 
    }    
    return gcdThusFar; 
  }
}

public class Experiment {
  public static void main(String[] args) {
    Fraction a, b; 

    a = new Fraction(1, 2); 
    b = new Fraction(1, 2); 

    System.out.println((a.add(b)).toString());     

  }
}

public class Fraction {
  int num, den; 
  Fraction(int num, int den) {
    int gcd = Math.gcd(java.lang.Math.abs(num), 
                       java.lang.Math.abs(den)); 
    this.num = num / gcd; 
    this.den = den / gcd; 
    if (this.den < 0) {
      this.den = - this.den; 
      this.num = - this.num; 
    } 
  }
  public String toString() {
    String fraction = this.num + "/" + this.den;
    return fraction;
  }
  public Fraction add(Fraction other) {
    return new Fraction(this.num * other.den + 
                        this.den * other.num, 
                        this.den * other.den); 
  } 
}

Wed Jul 16
Help Session tonight (LH102, 7-8pm).

Midterm Exam tomorrow in class (20-50 multiple-choice questions).

Lab Assignment on Thu is Lab Six perhaps combined with Lab Seven.

(Counts as Lab Six only, though. There is no Lab Assignment Seven.)

Mon no Lab Assignment. Lab Eight starts, due the Mon after that.

Next Thu: Practical Exam. Mon after that Lab Eight due, Lab Nine starts.

Tue Jul 15
Homework Three posted, is due next Monday.

Exam on Thursday, please practice with QuizSite exercises.

Help session on Wed night as always, here's an old midterm exam to practice.

Mon Jul 14
The first set of BlueJ Notes (for Chapters 1-4) have been posted. They will eventually survey the entire book. They are also supposed to help with the assigned homework. Hope you find them useful. Let us know if you need more help with them (or anything else).

Note there is a catch-up lab on Thu so there's nothing due until then, but you're more than welcome to turn things today so there's nothing due on Thu. The lab assignment today will be based on Lab Notes Six, while he catch-up lab assignment on Thu might also be based on both Lab Notes Six as well as Lab Notes Seven.

Here's a basic overview of the remaining homework assignments:

Homework Three: Write and explain ClockDisplay

Homework Four: Based on Chapter 7 of the BlueJ book (Eliza).

Homework Five: Based on Chapter 8 of the BlueJ book.

Homework Six: Based on Chapters 10-11 of the BlueJ book.

Homework Seven (and last): Based on Chapters 12, 13 of the BlueJ book.

In most you'll have to clearly describe a large program in a tutorial.

Sun Jul 13
Your tutorial for Homework Two should explain how you developed your program in stages very much like Lab Notes Four guided you through a similar development (class Student). That as well as any of the posted Lecture Notes that explain developing programs should be your model for the tutorial.

Sat Jul 12
Lecture notes for next week sketched.

Fri Jul 11
Homework Two can be turned in in QuizSite since Thu 4pm (dgerman_A201).

Can this help with the Homework at all?

public class Koob {
  private String what; 
  Koob() {
    this.what = ""; 
  }  
  void moo(String where) {
    if (where.length() >= 3) { 
      this.what = where; 
    } else {
      
    }
  }
  String boo() { 
    return this.what; 
  }
}

public class Experiment {
  public static void main(String[] args) {
    Koob a = new Koob(); 
    a.moo("ab"); 
    System.out.println(a.boo()); 
    a.moo("abc"); 
    System.out.println(a.boo()); 
    a.moo("abcd"); 
    System.out.println(a.boo()); 
    a.moo("a"); 
    System.out.println(a.boo()); 
    a.moo("xyz"); 
    System.out.println(a.boo()); 

  }
}

Thu Jul 10
Homework Two deadline extended to Monday evening at the end of the day.

What follows is your Lab Assignment for the lab today.

Define the following concepts (in writing):

  1. class
  2. object
  3. method
  4. instance method
  5. static method
  6. variable
  7. parameter
  8. local variable
  9. instance variable
  10. static variable
  11. constructor
  12. default no-arg constructor

Then explain this program (also in writing):

frilled.cs.indiana.edu%cat LabFive.java
class Momerath {
    static int a; 
    int b; 
    static void boo(Momerath b) {
	Momerath.a += 1; 
        b.b += 1; 
        System.out.println("boo: (" + Momerath.a + ", " + b.b + ")"); 
    }
    void hoo(Momerath other) {
	this.b += 1; 
        other.b += 1; 
        System.out.println("hoo: (" + this.b + ", " + other.b + ")"); 
    }
    public static void main(String[] args) {
	Momerath a = new Momerath(); 
	Momerath b = new Momerath(); 
	Momerath.boo(a); 
	Momerath.boo(a); 
	Momerath.boo(b); 
	Momerath.boo(new Momerath()); 
        a.hoo(a); 
        a.hoo(b); 
        b.hoo(new Momerath()); 
        (new Momerath()).hoo(a); 
        (new Momerath()).hoo(new Momerath()); 

    }
}
frilled.cs.indiana.edu%javac LabFive.java
frilled.cs.indiana.edu%java Momerath
boo: (1, 1)
boo: (2, 2)
boo: (3, 1)
boo: (4, 1)
hoo: (4, 4)
hoo: (5, 2)
hoo: (3, 1)
hoo: (1, 6)
hoo: (1, 1)
frilled.cs.indiana.edu%
Turn this in at the end of the lab today: a piece of paper with your answers.

We'll see you in lab later today.

Wed Jul 9
There's a help session tonight from 7-8pm in LH102.

Tentatively I'd like to solve this problem as if it were our Homework Two.

Note: this is Homework Two from Spring (and it appears in your ClassPak too).

Here's a solution to it:

class Robot {
    String direction;
    int x, y;
    String name;
    Robot(String n, int x, int y, String dir) {
	name = n; this.x = x; this.y = y; direction = dir; 
    } 
    void moveForward() {
	System.out.println("Robot " + name + " now moves forward."); 
	if (direction.equals("North")) {
	    y -= 1; 
	} else if (direction.equals("South")) {
	    y += 1; 
	} else if (direction.equals("East")) {
	    x += 1; 
	} else if (direction.equals("West")) {
	    x -= 1; 
	} else {
	    // nothing 
	}
    } 
    void turnLeft() {
	System.out.println("Robot " + name + " now turns left."); 
	if (direction.equals("North")) {
	    direction = "West"; 
	} else if (direction.equals("South")) {
	    direction = "East"; 	 
	} else if (direction.equals("East")) {
	    direction = "North"; 	 
	} else if (direction.equals("West")) {
	    direction = "South"; 	 
	} else {
	    // nothing 
	}
    }
    int getX() { return x; }
    int getY() { return y; }
    String direction() { return direction; } 
    void report() {
	System.out.println( "Robot " + name + " located at (" + x + 
			    ", " + y + ") facing " + direction ); 
    } 
}

Tue Jul 8
Here's an example of a test program for Homework Two:
class HomeworkTwo {
  public static void main(String[] args) {

    Book b = new Book("Soaked in Java", "Adrian German", 691);
    b.printAuthor(); 
    b.printTitle(); 
    b.setRefNumber("dag001"); 
    b.printDetails();
    System.out.println(b.getRefNumber()); 
    
    Book c = new Book("The mostly open source web", "Adrian German", 491);
    c.printAuthor(); 
    c.printTitle(); 
    c.printDetails(); // no ref number set yet
    c.setRefNumber("dag002"); 
    System.out.println(c.getRefNumber()); 
    c.printDetails(); // we should see the ref number now...    

    c.setRefNumber("d"); // should have no effect!

    b.borrow(); 
    b.borrow(); 
    b.borrow(); 

    System.out.println(b.getBorrowed()); // should be 3 

    System.out.println(c.getBorrowed()); // should be 0 

    b.printDetails(); // should show how many times the book was checked out

  }
}
There will be a review session on Wed 7-8pm in LH102 (tomorrow).

Most likely we'll discuss Homework Two.

But any topics are welcome: come prepared to ask questions.

Don't forget QuizSite has 6 batches of problems for practice.

Mon Jul 7
QuizSite has been activated (dgerman_A201) and loaded with 6 prep quizzes.

They're setting up some practice for the exam next week.

Here's the code developed in class today:

class Line {
  Point a, b; 
  double length() {
    return a.distanceTo(b); 
  }
  Line(Point u1, Point u2) {
    this.a = u1; 
    this.b = u2;
  }
}

class Experiment {
  public static void main(String[] args) {
    Point a = new Point(1, 2); 
    Point b = new Point(-2, -10); 
    Line line = new Line(a, b); 
    System.out.println(line.length()); 
  }
}

class Point {
  double x, y; 
  Point(double x, double y) { this.x = x; this.y = y; } 
  double distanceTo(Point o) {
    double dx = this.x - o.x; 
    double dy = this.y - o.y;     
    return Math.sqrt(dx * dx + dy * dy); 
  }
}
Here's the second experiment:
class Roots {
  public static void main(String[] args) {
    double n = 49; 
    double guess = 1; 
    while (Math.abs(guess * guess - n) > 0.000001) {
      System.out.println(guess); 
      guess = (guess + n /guess) / 2; 
    }
    System.out.println("Final answer: " + guess); 
  }
}

Fri-Sun Jul 5-6
Notes for next week sketched.

They need to be updated a bit, but they're accurate already.

Thu Jul 4
Here's Homework Two posted (and available also through a direct link).

Web forum for summer 2003 is now active.

Wed Jul 2
Homework Two will be posted today.

It's basically the union of (exercises) 2.44-51 in the BlueJ book.

I will pots the full text of the assignment on the web site.

My office hours are only in LH201D (from 3-4pm and 5-6pm).

Tue Jul 1
The BlueJ book and the CD are on reserve now at Swain.

My office hours are MTWR from 3-4pm and 5-6pm in LH201D or by appointment.

Richard's office hours are 5-7pm in LH016 on Wednesdays.

These office hours may change in the future but we will let you know in advance.

We will always be available by appointment (or walk-in).

Sriram's office hours are Tuesdays 6-8pm in LH016.

Mon Jun 30
Lab Assignment Two: read Lab Notes Two carefully then solve either this or this.

Remember that you have seen and understood Conversion already.

Sat-Sun Jun 28-29
Links to notes for next week posted. Note the files are from Spring 2003 and will be updated slightly Sunday night---just to make them from this time (second Summer session 2003) and remove some outdated references. Here also are some more links: to the ClassPak PDF and to the HTML ClassPak from Spring. Also to the entire web site from Spring 2003. I will be coming to both labs on Monday.

Here's the message I sent on Friday to the e-mail distribution list created then:

Date: Fri, 27 Jun 2003 12:22:40 -0500 (EST)
From: Adrian German <dgerman@cs.indiana.edu>
To: A201 Summer 2003 Distribution List <dgerman@indiana.edu>
Bcc: <the actual list> 
Subject: A201 Update


Dear A201/A597/I210 Friends,

I plan to post some help with Homework One and Lab Assignment Two
today. I also will be attending both labs on Monday. After that I
will be having two office hours per day (every day), at 2pm in my
office (LH201D) and at 5pm in LH016 for the rest of the semester.

I will also post links to notes for next week. I again will be out
of town from this afternoon until Sunday night going to Columbus OH
but when I return I will further update the web notes and offer some
more help by e-mail.

I am also going to extend Homework One one day (to Tuesday in class).
The hints that I will post might help. I hope that by now you realized
that problems can be tough even when they don't require any technical
knowledge. Getting some practice with these problems is (I believe) the
best possible warmup for learning computer programming in Java.

Also, please let me use this opportunity to thank Richard for his help
yesterday and I hope you enjoyed his lecture. Hope you have a good weekend
and please don't forget to check the web notes for updates (to be posted
within a few minutes, following this message).

Yours,
... Adrian

Fri Jun 27
Help with Homework One (which has been extended one day) has been posted.

E-mail distribution list will be created today.

Thu Jun 26
For the SDK that comes with the CD the PATH needs to be augmented with:
;c:\j2sdk1.4.0_03\bin;
(Careful with the semicolons, don't put too many or too few).

Also, I will be in Chicago in the morning (returning after 6pm in the evening) and Richard has graciously accepted to teach the lecture instead. If you have any questions or need any help please e-mail and I will get to your messages after 6pm when I return to Bloomington.

Wed Jun 25
Homework Assignment One has been posted, is due next week.

Tue Jun 24
Instructions for installing Java on your computer at home:

  1. Go to Sun's Java Tutorial Web Site

  2. On that page choose the First Steps section for your operating system.
    (I assume a Windows system below).

  3. There's a Checklist in which two are the most important steps.

  4. The first one is: download the SDK. (You can get it from the BlueJ CD).

  5. The second (more important one) contains the installation instructions.

  6. Make sure you set your PATH (and/or CLASSPATH) as described in the instructions.

Mon Jun 23
Second Summer session starts. The days are just packed. Welcome to A201!


Updated by Adrian German for A201/A597 and I210