November 30, 2006 2:10 PM

Session 26

Today we turned our string and file skills to a practical media computation task: the generation of a web page. The pages we create are "dynamic" in the sense that they rely on content that changes: the comic strip on a web page out on the web, and a randomly-selected quote from a file of quotes.

You can download all the material from class -- sample web pages, the Java programs, and the quotes file we used -- in this .zip file.

For next time, read Chapter 13 and study the PageGenerator class. And don't forget Homework 7, which is due tomorrow afternoon. You can bring the print-out to 305 ITT, the department office, any time. If I'm in, you can bring it on back; otherwise, the secretary will put it in my mailbox.


Posted by Eugene Wallingford | Permalink | Categories: Sessions

November 28, 2006 1:01 PM

Session 25

The main event today was our second exam. We spent the first few minutes learning how to create a double-clickable application (with a custom icon, no less!) for a Java program. We used our FoxTrotDownloader from last session as our demonstration program. You can follow along with the discussion on this tutorial page.

In class on Thursday, we will begin our discussion of generating web pages to complement our image and sound files. Be sure to read the first half of Chapter 13 to prepare.

Don't forget that Homework 7 is due on Friday afternoon. We will have one more assignment this semester, running from this Friday to the last day of classes.


Posted by Eugene Wallingford | Permalink | Categories: Sessions

November 21, 2006 2:42 PM

Homework 7: Drawing Pictures from a Simple Language

Write a class named GraphicsInterpreter that reads a sequence of graphics commands from a text file. The class should have a method named interpret that

  • takes a filename as input,
  • reads the commands contained in the file, and
  • returns a Picture on which the commands have been executed.

The method should create a blank 640x480 picture on which to drwa.

There are at least three kinds of commands:

  • line x1 y1 x2 y2

    The line command draws a straight line. For example, "line 10 20 300 400" draws a line from (10, 20) to (300, 400).

  • circle x y d

    The circle command draws, yes, a circle. For example, "circle 100 200 50" draws a circle whose center point is (100, 200) and whose radius is 50.

  • a command of your own design! It can draw a figure, write, text, ....

This assignment is worth 20 points.

You can use this main method for your class:

     public static void main( String[] args )
     {
       GraphicsInterpreter artist = new GraphicsInterpreter();
       String filename = FileChooser.getMediaPath( "commands.txt" );
       Picture p = artist.interpret( filename );
       p.show();
     }

Extra Credit Opportunities

Make it so that we can initialize a GraphicsInterpreter with a particular picture. If the object is created with a picture, then it draws on the given picture. If not, it uses a blank canvas. (1 point)

Create a commands.txt file that produces a picture that does something useful. For example, I could imagine a sequence of commands that create a poster to advertise a meeting. (1 point)

Deliverables

By the 4:00 PM on Friday, December 1, submit a zip file of a directory that contains these files:

  • GraphicsInterpreter.java
  • two different files that test your class, one named commands.txt
  • a Picture created by your program from commands.txt
following the submission instructions for the course.

For this assignment, you need to submit only one printout -- GraphicsInterpreter.java.


Posted by Eugene Wallingford | Permalink | Categories: Homework

November 21, 2006 2:39 PM

Session 24 -- Files and Objects

Being the last day before our second midterm, and the last day before a well-deserved break from classes, we mostly wrapped up some details today. We explored reading text files, and saw that the process bears a similarity to writing text files. We fiddled a bit more with strings and e-mail addresses, too.

Here are the slides (PDF) I used and a sanitized script of some of our Dr. Java interactions. We produced several classes: Student, StudentReader, and ProspectReader.

For a little bonus, I offered a program that reads not text, but an image, and not from a file, but from a URL! I don't expect you to be able to write this kind of code, especially the method that reads and writes the image. But you should be able to see some familiar structure in the code. If you want to have fun with web sites of your own choice, then do! Here is my FoxTrotDownloader.

For next time, prepare for the exam. It will focus on material since the last exam through Chapter 12 of the textbook.

Homework 7 will be posted in a matter of minutes!


Posted by Eugene Wallingford | Permalink | Categories: Sessions

November 16, 2006 2:10 PM

Session 23

Today, students laughed at me for being old. But I don't feel too bad. I am just glad that you all know how to make .zip files!

We expanded on our Die class example from last time to create a PowerBallEntry class. Why write a lot of code in a main() when we can create an object with that behavior? In Computer Science II, you will learn that there are great reasons to put all of your behavior in objects! For now, we see just one: it is a lot easier to reuse the behavior when we can create an object that does it.

From there, we ran one last test, to demonstrate just how hard it is to pick a winner in Powerball... Run EasyWinner -- but don't be in a hurry; it will probably take a while.

Finally, we began to explore splitting strings using a Student class. We left an open question: emailDomain() works for "@cs.uni.edu" but not "@gmail.com". Your job: fix it!

Here are the slides (PDF) I used and a script of some of our Dr. Java interactions.

For next time, start reading Chapter 13 of the textbook. Our second midterm exam will be Tuesday, November 28 -- a week from our next session, and the class day after Thanksgiving. Homework 7 will be posted next session.


Posted by Eugene Wallingford | Permalink | Categories: Sessions

November 14, 2006 4:18 PM

Session 22

Today, we extended our Die class to produce a sequence of unique values. Along the way, I hope we learned a bit about designing a method to perform a task with several layers of complexity.

We then revisited a method for DiffSound that writes the object to a file. It exposed many of the elements of writing files in Java -- which we will soon do much of, when generating web pages!

Here are the slides (PDF) I used and a script of some of our Dr. Java interactions. In addition to the Die and DiffSound classes, we also produced a simple program to mirror a String.

For next time, finish reading Chapter 12 of the textbook.

Note 1. Our second midterm exam will be Tuesday, November 28 -- the first class day after Thnaksgiving.

Note 2. Your next homework assignment is due next time.


Posted by Eugene Wallingford | Permalink | Categories: Sessions

November 09, 2006 3:01 PM

Homework 6: Creating a Simple Slideshow Program

Quick Overview

Your task this week is to write your first new class, one that represents simple slideshow objects. A slideshow consists of a collection of pictures to display and a collection of sounds to play. In the simplest form of slideshow, your program will play one sound file for each picture it displays.

Details, Details

  • Create a class named Slideshow and save it to a file named Slideshow.java.
  • A Slideshow keeps track of an array of Pictures and an array of Sounds. The class should have a constructor that lets users pass two arrays when creating a new Slideshow object.
  • Slideshow should have a method named show() that plays the slideshow. It should display each picture in its array, one at a time.
  • While a picture is showing, your object should play the corresponding sound file. In order to stop your program from proceeding while the sound is playing, be sure to use the blockingPlay() method of the Sound.
  • To display the pictures, start with an empty "canvas", a blank picture into which you can copy each of the images. After copying the image to display onto the canvase, ask the canvas to repaint.
  • You could use a large canvas, so that it is big enough to hold all of the images. If you do this, you could copy each pisture into the upper lefthand corner of the canvas or (better!) into the center of the canvas.
  • Alternatively, you could use a canvas of some convenient fixed size, say, a square of 800x800 or a rectangle of 640x480. If you do this, you should scale the picture to be displayed, making it either larger or smaller. To do this, you can use the scaling code from class or textbook.
  • Your class should have a main() method that creates a slideshow and shows it.
  • Use helper methods whereever you think appropriate to make your code easier to write, read, or understand.
  • Your function must retrieve the image files it uses from the directory specified by the media path. To do this you must use getMediaPath(). You must not use setMediaPath() or pickAFile() in your solution.
  • Your Slideshow.show() will use the show() and repaint() methods from the Picture class.

How We Will Grade Your Assignment

This assignment is worth 20 points.

We will...

  1. ... retrieve your submission from the submission system.
  2. ... put your Slideshow, Picture, and Sound classes into the bookClasses directory and all of your images and sounds into another folder.
  3. ... set the media path to the folder containing your images, using setMediaPath().
  4. ... open your Slideshow class in Dr. Java and compile it.
  5. ... execute your Slideshow class's main() method.
  6. ... watch your demonstration slideshow.
  7. ... use your Slideshow class to create and show a slideshow using our own images and sounds.

Extra Credit Opportunities

None yet. But I will appreciate demonstration slideshows that tell a nice story!

I am also inclined to consider extra credit for a slideshow that offers a second way to display a slideshow, where each sound is accompanied by multiple pictures, say, four pictures shown during a longer sound clip. A simple version of this would have n > 1 pictures for each sound, and each picture is shown for sound.length/n samples. If you want to give this a try, contact me!

Deliverables

By the 8:00 AM on Thursday, November 16, submit these files:

  • Slideshow.java
  • Picture.java
  • Sound.java
  • all of the images and sounds you use to in your demo slideshow
following the submission instructions for the course.

For this assignment, you need to submit only one printout -- Slideshow.java. You do not need to submit printouts of Picture.java or Sound.java (or of your images and sounds) -- but you must submit them all electronically.

You must submit your Picture and Sound classes, even if they don't contain any methods other than the original versions from your CD. This way, we don't have to worry about problems with different versions of those classes.


Posted by Eugene Wallingford | Permalink | Categories: Homework

November 09, 2006 2:58 PM

Session 21

Today, we learned some new Java (Random) and wrote another class (Die). Along the way, discussed class features and class design. By the time we reached our final version of Die, we had created a useful and flexible kind of object and a main() method that exercises it. We learned why and how to write a main() method.

We then moved on to the idea of a file. Along the way, we looked at the idea of javadoc and generated javadoc for our DiffSound and Sound files -- check out the result. Take a look at the javadoc for the Random class at the Java 1.4.2 javadoc site; you can find Random by scrolling down to java.util and finding it on that page, or click on All Classes link at the top of the page and scroll down to Random. The javadoc we generated for DiffSound and Sound looks just the same as Sun's!

Next time, we will look at files in more detail and start to generate text files for use on the web. We may even see Elvis Presley and George Carlin again!

Here are the slides (PDF) I used and a script of some of our Dr. Java interactions, including some material we didn't quite reach today. We'll use them next time. In addition to the Die class, we also just began to look at a new DiffSound class that knows how to write itself to a file.

For next time, finish reading Chapter 12 of the textbook.

Note 1. Recall that we pushed our first exam back one week, which means that we will want to pushd our second exam back a week, too. Exam 2 was originally scheduled for next Tuesday, November 14. We will not have the exam then; it will not happen until (at least) Tuesday, November 21.

Note 2. Your next homework assignment will be posted within a few minutes. Really!


Posted by Eugene Wallingford | Permalink | Categories: Sessions

November 07, 2006 2:33 PM

Session 20

Today, we spent a little more time discussing encoding and compression. We developed code that demonstrates how pixels are often represented, using a single int to encode three integer values in the range [0..255]. Then we implemented a decompress() method for our DiffSound objects and found that our compression is lossy but results in spoken sounds that can be understood.

Here are the slides (PDF) I used and a script of some of our Dr. Java interactions, and the files we produced:

  • a Pixel class that knows how to encode and decode itself,
  • a DiffSound class that now knows how to decompress itself, replete with javadoc comments, and
  • a version of Sound that compresses sounds more faithfully.

You can check out the javadoc generated automatically from the comments in Sound and DiffSound. We'll look at that briefly at the top of our next session.

For next time, begin reading Chapter 12 of the textbook. And watch for your next homework assignment -- I plan to post it no later than tomorrow morning bright and early!


Posted by Eugene Wallingford | Permalink | Categories: Sessions

November 02, 2006 3:10 PM

Session 19

Today, we returned manipulated sounds, but we did not play them. Instead, we did processed sounds as big arrays of sample values. We focused on how to store a bosy of data in less space, which is known as compression. We wrote our own algorithm for compressing sounds and then created a new kind of object to represent our encoding: DiffSound.

Here are the slides (PDF) I used and a script of some of our Dr. Java interactions, and the files we produced:

Read Chapter 10 of the textbook for our next session. I should have your next homework assignment ready by then.


Posted by Eugene Wallingford | Permalink | Categories: Sessions