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.
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.
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
The method should create a blank 640x480 picture on which to drwa.
There are at least three kinds of commands:
The line command draws a straight line. For example, "line 10 20 300 400" draws a line from (10, 20) to (300, 400).
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.
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:
For this assignment, you need to submit only one printout -- GraphicsInterpreter.java.
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!
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.
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.
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
How We Will Grade Your Assignment
This assignment is worth 20 points.
We will...
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:
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.
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!
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:
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!
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.