Published using Google Docs
Files CSE2130
Updated automatically every 5 minutes

CSE2130: Files and File structures 1

Computing Science 30

Set up: To make things easier and to be sure you do not save over similarly named files, you will be using multiple projects for this credit.  Inside the Netbeans Projects folder, create a new folder in called FilesActivities.  All the projects described below should go in this folder.

Class 1

Learning Activity: Read through the following website.  It will start off with some very obvious information but will then build to some new stuff and will set you up for the rest of the module.

Marked Assignment: Chapter 14 Questions ***

Create a new document called Chapter 14 Questions and share it with me.  Read the Chapter 14 handout from the book Java, Java, Java  up to and including page 697.  As you do, answer/d the following:

  1. What is a stream?
  2. Recreate the stream diagram at the bottom of page 692.  Use Insert... Drawing
  3. Define the terms record, fields and database
  4. What is the difference between a binary and a text file?
  5. What does it mean when it says that Java binary files are platform independent?
  6. We usually use the Reader and Writer classes & methods for writing Text to Files.  What streams does the text say we most often use to output text to the screen.?
  7. Define the terms filter and buffer

Class 2

Yesterday’s assignment is due before the end of class today.  It should not take you more than half the class.

Completed in class already: Marked Activity #2: Text Editor Using Swing

Due Date:

Pages 698-709 of the Chapter 14 handout (see above) walks you through creating a text editing program.  You are to read this section carefully and then .

Learning Activity

You are to watch 4 YouTube videos from the TheNewBoston Channel.  

They will explain a lot. You will have an assignment based on this code so you may want to complete the code along with them.  If you do so, create a project called Files_Videos.  To access these videos, click here. 

MarkedAssignment  - TheNewBoston Video Assignment

Step 1: In a project called Files_Videos, combine the code from the videos so that:

Step 2: Rewrite the addRecords method so that it takes in the three strings as parameters.

Step 3: Rewrite the main method so that the program uses a while loop to ask the user if she wants to:

  1. add a record
  2. exit

If they choose a, she is asked to enter an ID Number, first and last name.   After the user enters the names, the program calles addRecord and passes in the three parameters before looping back to the beginning.

For a small extra challenge, change the ID Number to an integer and have it increment automatically.

Evaluation: 80% for success, 20% for good coding and user friendliness

Class 3

Learning Activity: Chortle: Chapter 23 http://chortle.ccsu.edu/java5/index.html

Note: some of this chapter will be review, other parts will explain the theory behind files that the videos did not discuss.

Create a new project called Files_Ch23Learning.  Then recreate the program on page 4, saving it as Ch23_P4.java (different than what it says on the webpage) and then create a Ch23_data.txt in Notepad.  

  1. Test the program with several different numbers
  2. Alter the program to read 5 different integers all on separated by a space and the printed to the screen on separate lines.  You may do this with a loop using one num variable or in another manner.
  3. Recreate the file IOException error to see what it looks like on your program.  Then fix it when you are done.   We will learn more about Throwing and Catching errors later.

Still within the same project, save your program as Ch23_P6.java and Alter it to use the hasNextInt() method as shown on page 6.

  1. Test the program with 3-5 different text files, trying to think of different scenarios, preferably creating at least one error.
  2. The chapter mentions ‘Delimiters’.  If you do not fully know what this means, look it up using a dictionary.

Still within the same project, create the program on page 10, saving it as Ch23_P10.java

  1. Test it with several of the text files you created earlier in the chapter
  2. Test the error message by mistyping a file name
  3. Be sure to pay attention to what trim() does by adding some spaces around your file names.

Marked Assignment 2: Master of the Haiku

It will come as no surprise to you that Mr. Couprie is world renowned as the Master of the Haiku.  Using the program on page 12 of Chapter 23 as a starting point, create a project called Files_Haiku with HaikuMain as your main class.  Alter the program so that it allows me to:

Class 4

Learning Activity: Read through the rest Chapter 23 then complete the Review (a link from the main index page, to the right of the main chapter) http://chortle.ccsu.edu/java5/index.html

Marked Assignment 3: Chapter 23 Exercises

Create a new project called Files_CH23Exercises.  Then Complete any TWO of the Chapter 23 exercises, saving them as Ch23Ex_.java with the _ replaced by the exercise number you chose.  The exercises can be found as a link from the main index page, to the right of hte main chapter. http://chortle.ccsu.edu/java5/index.html

Class 5

Finish yesterday’s activities

Learning Activity: Chortle: Chapter 24 http://chortle.ccsu.edu/java5/index.html

Create a new project called Files_Ch24Learning.  Then, complete the program on page 4 saving it as Ch24_P4.java.

  1. Test it with a few different variations of your data file
  2. Recreate the error on page 6
  3. Read through the next examples in the chapter and trace (ie read carefully) through the programs to be sure you understand what they are doing.  You do not need to actually write and test thiese programs if you understand them from reading.
  4. Note: Carefully work through the use of Sentinel values on page 15.  Sentinel values will become very important over time.

Learning Activity: Complete the Chapter 24 review

My Computer Breathes

Life as its Science Strengthens

My Mind like Barbell

By Master of the Haiku, Scott Couprie

Copyright 2010

Marked Assignment:

Create a new project called Files_CH24Exercises.  Then complete exercise ONE only, saving the file as Ch24Ex1.java. The exercises can be found as a link from the main index page, to the right of the main chapter. http://chortle.ccsu.edu/java5/index.html.

Extra Activity for those ahead:

Chapter 24B has some interesting information on how to format your numbers when printing to files.  Skim this chapter quickly.  You need to get a feel for what they mean by “formatting” and to see what is possible should you need to use it in the future.  IB students may need this for their dossiers.

Class 6-7

Learning activity: Text File Review

Go to http://dl.dropbox.com/u/239179/mulkeyibcs/Home/notes_and_worksheets.htm and then find the link to Text File Intro.  Feel free to test the code if you wish (requires EasyApp.java, which is a separate class and can be found on top of link) but the comment section at the bottom of the file is very good at explaining how the Read and Write processes work for files.  Read through the code and the comments at the bottom.

look at:

Learning Activity: Sorting a Text File

Go to http://dl.dropbox.com/u/239179/mulkeyibcs/Home/notes_and_worksheets.htm and then find the link to Sorting a Text File.

Next project tests skills

Of files and other things

Go well my children

By Master of the Haiku, Scott Couprie

Copyright 2010

Marked Activity: CIA Factbook ***

Note: this is likely a two day project.

Go to http://dl.dropbox.com/u/239179/mulkeyibcs/Home/notes_and_worksheets.htm and then find the link to CIA Fact Book Files.

Class 8 & 9

Marked Activity: Random Access Files ***

Go to http://dl.dropbox.com/u/239179/mulkeyibcs/Home/notes_and_worksheets.htm and then find the link to RandomAccessFile Intro.  

Classes 10-14

Activities to be announced.  Will cover:

For Really Advanced Students Only ***

Zonker’s File Fable – Go to http://dl.dropbox.com/u/239179/mulkeyibcs/Home/notes_and_worksheets.htm and then find the link to Zonker’s File Fable.  Read the story and implement the code.

For Really Advanced Students with Good Swing Skills Only

For a big challenge, check out the ASCIImations in CS1/CS2 section of this site.  http://nifty.stanford.edu/2007/reed-asciimations/

Classes 15ish

Final Exam - This exam will likely be a “no help” assignment that will involve creating and opening a text file.  It may also involve sorting.  Details to be announced in class.