CPSC 124: Lab 10
Using Files

FOR THIS FINAL LAB OF THE COURSE, there is just one exercise. I hope that you will be able to complete this exercise during lab and turn it in at the end of lab. If you need more time, let me know.

Start by copying the folder "Lab 10 Files Starter" from the file server. This folder contains a version of the KaleidaSketch program that you worked on in a previous lab. This version can correctly redraw itself. It uses arrays to store data about the curves that the user has sketched. The arrays are used in the paint() method of KaleidaSketchCanvas to redraw all the curves.

(This version of KaleidaSketch is implemented as a standalone application rather than an applet. It has a main program that creates a Frame. This Frame contains a Kaleidasketch applet, and it has a menu that includes "Load" and "Save" commands for working with files. I have done things this way to demonstrate how applets can be used in standalone programs and how standard pull-down menus can be used. You can read the comments on the main program, "KaleidaSketchProgram.java", if you want to learn more about this. However, this is not the real point of today's lab.)

To begin the lab, open the project file in the "Lab 10 Files Starter" folder and open the file "KaleidaSketchCanvas.java". The exercise for this lab is to complete the definition of the load() method in this file. The method should use a FileDialog to allow the user to select a data file. This file is supposed to contain data for a sketch that has previously been saved by the save() method. A sample data file, "sketch1.dat", is available in the folder. You can make more data files by running the KaleidaSketchProgram and using its Save command to save the sketches you draw.

The load() method you write should open the file, wrap it in an AsciiInputStream, and read the data it contains. Use try...catch statements to catch any errors along the way. If the data is read without error, then the sketch from the file should be displayed. Note that you have to read the data from the file in exactly the same order that it was written by the save() method. (The data from the file has to replace the data in the instance variables x, y, pointCt, and backColorIndex -- but don't change the values in these variables until you have successfully read all the data from the file.)

End-of-Course Info

The final exam is scheduled for Monday, November 25, at 1:30 PM, in our regular classroom. It will be five or six pages long and will cover material from the entire course. At least half of the exam will be on material covered since the second test, that is, on chapters 7 and 8.

The final programming assignment is due at the final exam. Turn it in earlier, if possible. I expect the Rosenberg computer lab to be open during reading period at least from 1:00 PM to 1:00 AM on Wednesday and Thursday, and from 1:00 PM to 12:00 midnight on Friday.

The grade for the course is computed based on the following components: first test, second test, final exam, quizzes, lab reports, and programming assignments. I have decided that in determining your final grade for the course, I will drop the lowest grade among these six components. If you decide to skip the final exam, then that is the grade that will be dropped. (If you know in advance that you won't take the final, please let me know so that I won't have to make a copy for you.)

[ Lab Index | Online Notes ]