Second Summer 2005


Sun Aug 13
Final grades will be turned in Sunday morning.

Fri-Sat Aug 11-12
I am available by appointment, please use this script to make an appointment.

Thu Aug 11
It is a privilege to be offered the opportunity to make up an exam.

Such an opportunity will be offered during lab today (Practical Makeup).

The FINAL EXAM is in class today (3:30-5:15pm).

Wed Aug 10
Lecture notes updated with the code developed in class.

Tue Aug 9
Code developed yesterday in class and in LH115 between 7:30pm and 10:00pm now posted in lecture notes.

Mon Aug 8
There are 17 more students who need to pass the TBS. Tonight in lab: TBS IV.

(Half of these ALMOST PASSED the previous test, so the chances look good.)

Many thanks to Lebogang Molefi for coming to our office hour last night.

A summary of what we discussed is included below:

class StringTokenizer {
  String line;
  StringTokenizer (String line) {
    this.line = line.trim();
  }
  boolean hasMoreTokens() {
    return line.length() != 0;
  }
  String nextToken() {
    if (this.hasMoreTokens()) {
      String token = "";
      int i = 0;
      while (i < line.length() && line.charAt(i) != ' ') {
        token = token + line.charAt(i);
        i = i + 1;
      }
      if (i >= line.length()) line = "";
      else line = line.substring(i);
      line = line.trim();
      return token;
    } else {
      return null;
    }
  }
}
The code above is small, but the problem is not that immediate.

So it's a good exercise.

Sun Aug 7
Reminder that today we still have office hours in LH115 7:30pm-8:30pm.

Many thanks to Lebo Molefi and Charles Calligan for coming last night (Sat night).

We discussed these problems:

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

class OmitLongWords {
  public static void main(String[] args) throws Exception {
    process(args[0], Integer.parseInt(args[1])); 
  } 
  public static void process(String fileName, int len) throws Exception { 
    BufferedReader b = new BufferedReader(new FileReader(fileName)); 
    String line = b.readLine(); 
    while (line != null) {
      StringTokenizer st = new StringTokenizer(line); 
      while (st.hasMoreTokens()) {
        String token = st.nextToken(); 
        if (token.length() <= len) 
          System.out.println(token); 
      } 
      line = b.readLine(); 
    }
  } 
} 
Writing out only every nth line in a file:
class EveryNthLine throws Exception {
  public static void main(String[] args) {
    generateData(args[0], 1000); 
    extractLines(args[0], Integer.parseInt(args[1])); 
  } 
  public static void generateData(String fileName, int numOfLines) /* throws Exception */ {
    FileWriter outStream = new FileWriter(fileName); 
    for (int i = 0; i < numOfLines; i++) {
      outStream.write("Line no. " + i + " of the file " + fileName + "\n"); 
    } 
    outStream.close(); 
  } 
  public static void extractLines(String fileName, int period) throws Exception {
    BufferedReader b = new BufferedReader(new FileReader(fileName)); 
    String line = b.readLine(); 
    int count = 1; 
    while (line != null) {
      if (count % period == 0) {
        System.out.println(line); 
      } 
      line = b.readLine(); 
      count += 1; 
    }
  } 
} 
We also discussed for loops vs. while loops.

Questions were like these:

  1. How do you print the chars in a String, one per line?
    Answer: using a for loop seems to be the most natural solution.
    Exercise: do it using a while loop instead.

  2. How do you count the number of lines in a file?
    Answer: using a while loop seems to be the most natural solution.
    Exercise: do it using a for loop instead.

  3. How do you print the tokens in a sentence, one per line?
    Answer: using a while loop seems to be the most natural solution.
    Exercise: do it using a for loop instead.

  4. How do you calculate the square root of n using successive approximations?
    Answer: using a while loop seems to be the most natural approach.
    Exercise: do it using a for loop instead.

  5. Same questions for finding the max in a two-dimensional array of ints.

  6. Same questions for bubble sort.

  7. Same questions for selection sort.

  8. Same question for calculating the standard deviation of a sequence of numbers stored in a double[].

Sat Aug 6
Reminder that today and tomorrow we still have office hours in LH115 7:30pm-8:30pm.

Many thanks to Lebo Molefi and Charles Calligan for coming last night (Fri night).

We discussed this problem:

public class Exam {
  public static void main(String[] args) {
    Room[][] a = new Room[2][3];
    for (int i = 0; i < a.length; i++)
      for (int j = 0; j < a[i].length; j++)
        a[i][j] = new Room("F" + i + ", #" + j,
                           Math.random() * 6 + 2, Math.random() * 8 + 2);
    show(a);
    System.out.println("So the largest room is: " + largestRoom(a).getName());
  }
  public static void show(Room[][] m) {
    for (int i = 0; i < m.length; i++)
      for (int j = 0; j  largest.getArea())
          largest = mansion[i][j];
    return largest;
  }
}

class Room {
  double width;
  double length;
  String name;
  Room(String n, double w, double l) {
    length = l; width = w; name = n;
  }
  double getWidth() { return width;}
  double getLength() { return length;}
  double getArea() { return length * width;}
  String getName() { return name;}
  void report() {
    System.out.println(name + " " + getArea());
  }
}

Fri Aug 5
A summary of the steps for the bonus project is posted in 08/08/05 lecture notes.

Here are solutions to TBS (III) administered last night:

class Exam {
  public static int countSpaces(String line) {
    for (int i = 0, sum = 0; i < line.length(); i++) 
      if (line.charAt(i) == ' ') 
        sum += 1; 
    return sum; 
  } 

  public static double calculate(String fileName) throws IOException {
    BufferedReader b = new BufferedReader(new FileReader(fileName)); 
    String line = b.readLine(); 
    double chars = 0, spaces = 0; 
    while (line != null) {
      chars += line.length(); 
      spaces += Exam.countSpaces(line); 
    } 
    return spaces/chars; 
  } 

  public static int find(int[] a, int value) {
    int i;  
    for (i = a.length - 1; i >= 0; i--)
      if (a[i] >= value) 
        return i; 
    return i; // notice we return -1 if search is unsuccessful
  } 
} 

Thu Aug 4
The text of TBS (II) and its solutions have been posted, as discussed in class.

Wed Aug 3
TBS (II) will be administered in class today.

Adrian's office hours during August 2-12:

Please come to get help, or make up exams and/or assignments.

Tue Aug 2
Review class today, preparing for the TBS tomorrow.

Mon Aug 1
TBS grades posted. Exams to be returned in class.

Lab Assignment for today: implement the three problems and submit them.

Sun July 31
Grades will be posted on Monday, feedback will be given in labs by Adrian.

TBS make-up (re-take) is scheduled for Wednesday during the lecture.

Sat July 30
Here's a solution to Problem 3 on the exam, worked out with Sourav on Friday afternoon:
import javax.swing.*; 
import java.awt.*; 
import java.awt.event.*; 

public class Two extends JFrame implements ActionListener {
    public static void main(String[] args) {
	Two a = new Two(); 
    }
    JButton a, b; 
    public Two() {
	Container a = this.getContentPane();
	a.setLayout(new FlowLayout()); 
	a.add(this.a = new JButton("One"));
	a.add(this.b = new JButton("Two"));
	pack(); 
        setTitle("exam"); 
	setVisible(true); 
	setSize(400, 400); 
	this.a.addActionListener(this); 
        this.b.addActionListener(this); 
    }
    public void actionPerformed(ActionEvent e) {
	System.out.println("Ouch!..."); 
        if (e.getSource() == this.a) this.setSize(800, 800); 
	else this.setSize(200, 200); 
    }
}
Here's also a possible solution to a problem you might be working on.

Here's the problem we discussed in class on Thursday (that started with a question from Paul Touloukian).

Fri July 29
Just a reminder, Fridays I am available 1-4pm (in LH201D) or by appointment.

Thu July 28
Practical Exam in labs today.

You can use everything you want:

just don't communicate with anyone except the course instructors.

Review the basic material in chapters 1-14 in the text.

Exercises on the test would be 6-8 in number, like the ones in OnCourse for the TBS.

Wed July 27
Between July 27 and Aug 12

for extra help (Adrian's office hour).

I remain available during the day 9-10am and 1-2pm or by appointment MTWR.

Fridays I am available 1pm-4pm or by appointment.

Tue July 26
Deploying servlets requires a web.xml very much like this:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

    <servlet>
        <servlet-name>One</servlet-name>
        <servlet-class>One</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>One</servlet-name>
        <url-pattern>/servlet/One</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>Fv2_3</servlet-name>
        <servlet-class>Two</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>Fv2_3</servlet-name>
        <url-pattern>/servlet/Fancy</url-pattern>
    </servlet-mapping>


</web-app>

Mon July 25
We're combining the lab quizzes for this week into a quiz due next Monday (at the end of the lab).

The quiz will be: describe (succinctly) the steps necessary to install Tomcat.

The lab work for this week will be: have Tomcat installed.

Lecture Notes for July 20 indicate how you can install Tomcat 5.5.9 in your burrowww account.

Lecture Notes for July 21 contain the list of usernames and ports.

TBS in class today, Jeremy is proctoring, I am in Chicago, returning in the evening.

Sat-Sun July 23-24
Lab Notes Nine posted:

Those who crave a semester project can and should try to rewrite this game in an object-oriented way.

This used to be an old A201 Lab as you can see.

Fri July 22
Thanks to
Jeremy Martin
for coming up with this very instructive variation on Homework Five:

Java code by David Ward (see original thread with details).

Thu July 21
Today in lab we create burrowww accounts.

In class we also will go over the account creation process.

Wed July 20
Both today and tomorrow in class we will review for the TBS scheduled for Monday.

The quiz tomorrow in lab will be open-book, at least a page, up to two pages:

Be specific. Be very specific!

For breaks we will use from now on:

Tue July 19
Jeremy's new office hours are 10-11am on Tuesday and 1:30-2:30pm on Tuesday.

They are still in the same location.

Mon July 18
Homework Five posted,

Homework Six posted,

The first Test of Basic Skills is

The Practical Exam for this class

Details on all of these to be posted tonight, along with all the grades thus far.

Sat-Sun July 16-17
A new web forum will become active on Monday.

Use your IU network ID to log in, the messages will be automatically signed with your username.

TBS details will be announced on Monday (tomorrow).

Fri July 15
Russell and I will be in Indianapolis today on an OnCourseCL related project.

So we won't be able to keep any office hours today.

Exam grades will be posted soon. Regular office hours resume on Monday morning.

I am available for appointments over the weekend, so e-mail me (dgerman@indiana.edu) if you need help.

Thu July 14
Lecture notes for July 13 updated with code developed in class and in SE015.

MIDTERM EXAM 3:30-5:15pm in class today (Thursday, July 14).

Here's the quiz for the lab on Thursday (like 7.15/345 in Homework Two):

Design and implement a program that plays Time Bomb with the user.
Here's how the game works:
  • the computer picks a secret word and then prints one asterisk for each letter in the word.
  • The user guesses at the letters in the word.
  • For every correct guess, an asterisk is replaced by a letter.
  • For every incorrect guess the time bomb's fuse grows shorter.
  • When the fuse disappears, after say, six incorrect guesses, the bomb explodes.
Here's a solution that would get all the points.
You are more than welcome to write a reasonably comparable (or equivalent) solution.
Reminder:

Wed July 13
Midterm Review tonight (Wednesday, July 13) in Swain East 105 (SE105).

The OnCourse part of TBS materials is now complete. One more list will be posted tomorrow, and we'll be ready for it.

Thanks to


Yigang Huang
for noticing that Problem 7.16 has a very simple solution (which is not acceptable for Homework Four).

Here's a lesson we will be going over at some point (perhaps even today).

Tue July 12
The code used yesterday (the russian roulette included).

Thanks to

Melissa Troyer and Doug Ranger
for coming up with the following interesting exercise:
void sort(Shape[] a) {
  boolean done = true; 
  do {
    for (int i = 0; i < a.length - 1; i++) {
      done = true && done || (i == 0);
      if (a[i].area() > a[i+1].area()) {
        Shape temp = a[i]; 
        a[i] = a[i+1]; 
        a[i+1] = temp; 
        done = false; 
      } 
    } 
  } while (! done); 
}
Notice that it looks like the code is wrong.

Please start practicing with the 11 TBS Practice Quizzes (~130 items) posted in OnCourse.

There will be a larger document to be posted tonight that would complete the TBS Review.

Here are the notes used last summer and last spring with respect to file I/O and such.

Mon July 11
Labs and minute paper grades updated in the gradebook.

Portions of Chapters 9 and 11 are useful in the lab today.

Sat-Sun July 9-10
The quiz on Monday will be the following part of Homework Three:

  • the definition of the class Point
  • the definition of the class Line
  • the definition of the class Triangle
  • the definition of a Experiment class that only has a main method

All four classes are required on the quiz. They are listed below:

class Experiment {
  public static void main(String[] args) {
      Triangle a = new Triangle(new Point(0, 3), 
                                new Point(4, 0), 
                                Point.origin); 
      System.out.println(a.area()); // should be 6.0 
  }
}
class Triangle {
    Line a, b, c; 
    Triangle (Point a, Point b, Point c) {
        this.a = new Line(a, b); 
        this.b = new Line(a, c); 
        this.c = new Line(b, c); 
    }
    double area() {
        double s = (this.a.length() + this.b.length() + this.c.length()) / 2; 
        return Math.sqrt(s * (s - a.length()) * 
                             (s - b.length()) * 
                             (s - c.length())); 
    }
}
class Line {
    Point a, b;
    double length() {
        return a.distanceTo(b);
    }
    Line(Point u1, Point u2) {
        this.a = u1;
        this.b = u2;
    }
}
class Point {
    double x, y;
    Point(double x, double y) { this.x = x; this.y = y; }
    Point() { this(0, 0); }
    static Point origin = new Point(); 
    double distanceTo(Point other) {
        double dx = this.x - other.x;
        double dy = this.y - other.y;
        return Math.sqrt(dx * dx + dy * dy);
    }
}

Thu-Fri July 7-8
Here's some of the code developed in class on Thu:
import java.io.*; 

class Channel {
  BufferedReader reader; 
  Channel() {
    reader = new BufferedReader(new InputStreamReader(System.in)); 
  } 
  String readLine() {
    String line = ""; 
    try {
      line = reader.readLine(); 
    } catch (Exception e) { }
    return line; 
  } 
  Channel(String file) {
    try { 
      reader = 
        new BufferedReader(
          new InputStreamReader(
            new FileInputStream(file))); 
    } catch (Exception e) { System.exit(0); } 
  } 
  public static void main(String[] args) {
    Channel c = new Channel(args[0]); 
    String line = c.readLine(); 
    while (line != null) { 
      System.out.println(line); 
      line = c.readLine(); 
    } 
    Channel b = new Channel(); 

    line = b.readLine(); 
    while (! line.equals("quit")) { 
      System.out.println(line); 
      line = b.readLine(); 
    } 

  } 
}
As you can see, reading from files or from the keyboard is essentially the same.

Wed July 6
The code discussed in class yesterday has been posted.

Slides one, two (and three) used in A201 might help.

Tue July 5
The notes for Lab Five have been posted.

Mon July 4
Homework Three has been posted, is due Thursday at the end of the day.

Sat-Sun July 2-3
Still working on the grades, to be updated on Monday.

A combination of chapter 8 and 9 will start our lecture on Tuesday.

Here's the problem: write a program that

The quiz next Monday will be on sorting (more details in class).

Also, from now on we will have a new section in the lecture entitled "Interview with a student."

Fri July 1
Grades will be updated tonight.

The lab quiz for Thu July 7 is: one of the first three quizzes (randomly selected).

Thu Jun 30
Lab Notes for today posted. TBS review to follow.

Note: the TBS review will be based entirely on your textbook.

Today in class we will look at this program:

import javax.swing.*; 
import java.awt.event.*; 
import java.awt.*; 

class Screen extends JPanel implements KeyListener {

    public void keyPressed(KeyEvent e) { 
	switch (e.getKeyCode()) {
	case 40:
	    System.out.println("down");
	    break;
	case 38:
	    System.out.println("up");
	    break;
	case 37:
	    System.out.println("left");
	    break;
	case 39:
	    System.out.println("right");
	    break;
	case KeyEvent.VK_KP_RIGHT:
	    System.out.println("right");
	    break;
	default:
	    System.out.println("some other key: " + e.getKeyCode());
	    break;
	}
    } 

    public void keyReleased(KeyEvent e) { 
	System.out.println("key released"); 
    } 

    public void keyTyped(KeyEvent e) { 
	System.out.println("key typed"); 	
    } 

    Screen() {
	setBackground(Color.white); 
        addKeyListener(this); 
    } 

}

class Example extends JFrame {
    public static void main(String[] args) {
	Example a = new Example(); 
    }
    Example() {
	getContentPane().setLayout(new BorderLayout()); 
        Screen a = new Screen(); 
	getContentPane().add("Center", a); 
	this.setSize(400, 400); 
	this.setVisible(true); 
	System.out.println(KeyEvent.VK_KP_RIGHT); 
	a.requestFocusInWindow(); 
    }
}
Code for last Monday: TemperatureJPanel.java, Test.java.

Code for today: One.java, Test.java and Screen.java.

Wed Jun 29
Many thanks to Seun and Chandler
for their contribution to the lecture yesterday.

Tue Jun 28
Reminder:

Homework Two is posted, we need to start right away.

Mon Jun 27
Lab and lecture notes for today are up, having been posted Sun afternoon.

Note that if we replace One by Test (below):

public class Test extends JFrame {
    Test() {
        Container contentPane = this.getContentPane(); 
	contentPane.setLayout(new BorderLayout()); 
        contentPane.add("Center", new Screen()); 
	pack();
	setTitle("The other way around."); 
	setVisible(true); 
	setSize(400, 400); 
    }
    public static void main(String[] args) {
	new Test();       
    }
}
the application runs in a JFrame (instead of a JApplet).

Recall the class diagram was:

Other than the replacement of Test for One everything else is still the same.

Sat-Sun Jun 25-26
Homework Two has been posted (more details might be added, for the asking).

The lab test at the beginning of the lab on Monday is on class KeyboardReader (p. 157).

You will be asked to write the class and an example of its use (in a main method).

Here is the code developed in class on Thu (Jun 23).

Fri Jun 24
Sent to the distribution list:
Date: Fri, 24 Jun 2005 00:21:27 -0500 (EST)
From: Adrian German 
Subject: Office Hours for A202 Summer 2005  

Dear A202/A598 and I211 Friends,

Today, Friday June 24, we will be available as follows:

  1. Adrian 9am-4pm in LH201D (Lindley second floor)

  2. Russell 1pm-3:30pm also in LH201D (Lindley second floor, same office)

Please come if you need help.

Office hours in general:

  1. Adrian MTWRF 9-10am and 1-2pm LH201D (Lindley second floor)

  2. Russell M 1:15-3:15pm in LH201D (Lindley second floor)

  3. Jeremy T 9:30-11:30am in LH401A (Lindley fourth floor)

We want to make this semester the best ever, so please write to us if
anything is not quite working for you and we will be glad to help.

... Adrian

Thu Jun 23
Lab Notes for today have been posted.

Here's today's lab assignment solution, posted so you can practice submitting it to OnCourse at the end of the lab.

Notice that OnCourse contains dropboxes for Lab Assignments 1, 2 and Homework Assignments 1 and 2 already.

Wed Jun 22
Just a reminder:

Sorry for any confusion I may have created during the first two days.

The lecture notes for yesterday have been updated with the code written in class.

More lecture notes for today and tomorrow are being posted now.

Tue Jun 21
Here's the schedule listed in OneStart for this class.

The lab test would be announced two days ahead of the lab always.

For Thursday the test (closed-book and written) asks you to:

The solution to this problem will be worked out in class today.

Reading assignment for tomorrow: Chapters 2 and 3.

Notes for today's lecture have been posted.

Take a look at the KeyboardReader class developed on p. 157.

It's similar to what we developed at the end of A201 in Spring 2005.

Mon Jun 20
Reading assignment for tomorrow: Chapters 0 and 1.

First lecture in LH102 at 3:30pm.

Labs are MR 5:30-7:15pm in BH308/118.

Perhaps these slides will be useful today.

Fri Jun 17
Second Summer session starts.

No class today, our schedule is MTWR.


Updated by Adrian German for A202/A598 and I211