![]() |
![]() Second Summer 2005
|
Sun Aug 13
Fri-Sat Aug 11-12
Thu Aug 11
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
Tue Aug 9
Mon Aug 8
(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:
The code above is small, but the problem is not that immediate.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; } } }
So it's a good exercise.
Sun Aug 7
Many thanks to Lebo Molefi and Charles Calligan for coming last night (Sat night).
We discussed these problems:
Writing out only every nth line in a file: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(); } } }
We also discussedclass 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; } } }
for
loops vs. while
loops. Questions were like these:
for
loop seems to be the most natural solution. while
loop instead.
while
loop seems to be the most natural solution. for
loop instead.
while
loop seems to be the most natural solution. for
loop instead.
n
using successive approximations? while
loop seems to be the most natural approach. for
loop instead.
double[]
.
Sat Aug 6
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; jlargest.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
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
Wed Aug 3
Adrian's office hours during August 2-12:
Please come to get help, or make up exams and/or assignments.
Tue Aug 2
Mon Aug 1
Lab Assignment for today: implement the three problems and submit them.
Sun July 31
TBS make-up (re-take) is scheduled for Wednesday during the lecture.
Sat July 30
Here's also a possible solution to a problem you might be working on.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 the problem we discussed in class on Thursday (that started with a question from Paul Touloukian).
Fri July 29
Thu July 28
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
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
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
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
GenericClient.java
should be placed on the desktop, the server in your burrowww
account.
www.cs.indiana.edu
, port 80
, to test GenericClient.java
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
for coming up with this very instructive variation on Homework Five:
![]()
Jeremy Martin
Unicorn
)
Java code by David Ward (see original thread with details).
Thu July 21
burrowww
accounts. In class we also will go over the account creation process.
Wed July 20
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
They are still in the same location.
Mon July 18
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
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
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
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.Reminder:
Here's how the game works:Here's a solution that would get all the points.
- 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.
You are more than welcome to write a reasonably comparable (or equivalent) solution.
Wed July 13
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
for noticing that Problem 7.16 has a very simple solution (which is not acceptable for Homework Four).
Yigang Huang
Here's a lesson we will be going over at some point (perhaps even today).
Tue July 12
Thanks to
for coming up with the following interesting exercise:
![]()
Melissa Troyer and Doug Ranger
Notice that it looks like the code is wrong.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); }
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
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:
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
As you can see, reading from files or from the keyboard is essentially the same.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(); } } }
Wed July 6
Slides one, two (and three) used in A201 might help.
Tue July 5
Mon July 4
Sat-Sun July 2-3
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
The lab quiz for Thu July 7 is: one of the first three quizzes (randomly selected).
Thu Jun 30
Note: the TBS review will be based entirely on your textbook.
Today in class we will look at this program:
Code for last Monday: TemperatureJPanel.java, Test.java.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 today: One.java, Test.java and Screen.java.
Wed Jun 29
![]() | ![]() |
Tue Jun 28
Homework Two is posted, we need to start right away.
Mon Jun 27
Note that if we replace One
by Test
(below):
the application runs in apublic 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(); } }
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
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
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
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
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
The lab test would be announced two days ahead of the lab always.
For Thursday the test (closed-book and written) asks you to:
main
)
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
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
No class today, our schedule is MTWR.