Friday, October 30, 2009

Homework 7: Field Notebook

For this homework you will implement a minimal field notebook, as might be used by a bird or butterfly watcher on the field (on her Android phone, one presumes). Your application will need to implement at least three classes:
  1. Reading is a specific observation that the user makes. This class has data members
    1. date of type Date, the date of the reading, which you will assign automatically to the current time.
    2. species is a String which is the name of the species of animal the user saw.
    3. count is an int that is the number of animals the user saw.
    4. comment a String comment
  2. Notebook is a collection of up to 100 readings. It should support, adding a new reading, printing, saving to a file, and reading back from a file.
  3. NegativeCountException is an Exception that you will raise if the user ever tries to enter a negative number of animals. Your program will throw this exception and also catch it, so the program does not crash.

Your program will support the saving of the whole notebook to a file and the subsequent loading of a notebook from a file. The whole thing will be controlled via a text-based interface, as such:

Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:r
Species name:swallowtails
Count:3
Comment:Fluttering in the sunshine.
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:r
Species name:Jezebel
Count:11
Comment:Hard to count in the daylight.
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:l
Fri Oct 30 14:11:31 EDT 2009 swallowtails 3 Fluttering in the sunshine.
Fri Oct 30 14:12:02 EDT 2009 Jezebel 11 Hard to count in the daylight.

Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:r
Species name:Duke of Burgundy
Count:1
Comment:Did not expect to see this one here!
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:l
Fri Oct 30 14:11:31 EDT 2009 swallowtails 3 Fluttering in the sunshine.
Fri Oct 30 14:12:02 EDT 2009 Jezebel 11 Hard to count in the daylight.
Fri Oct 30 14:12:37 EDT 2009 Duke of Burgundy 1 Did not expect to see this one here!

Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:w
Enter name of file to write to:notebook.dat
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:l
Fri Oct 30 14:11:31 EDT 2009 swallowtails 3 Fluttering in the sunshine.
Fri Oct 30 14:12:02 EDT 2009 Jezebel 11 Hard to count in the daylight.
Fri Oct 30 14:12:37 EDT 2009 Duke of Burgundy 1 Did not expect to see this one here!

Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:q
Bye bye. //at this point the program stops.

//we start it again
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:l

Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:o
Enter name of file to read:notebook.dat
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:l
Fri Oct 30 14:11:31 EDT 2009 swallowtails 3 Fluttering in the sunshine.
Fri Oct 30 14:12:02 EDT 2009 Jezebel 11 Hard to count in the daylight.
Fri Oct 30 14:12:37 EDT 2009 Duke of Burgundy 1 Did not expect to see this one here!

Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:r
Species name:Speckled wood
Count:200
Comment:A gaggle of butterflies.
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:l
Fri Oct 30 14:11:31 EDT 2009 swallowtails 3 Fluttering in the sunshine.
Fri Oct 30 14:12:02 EDT 2009 Jezebel 11 Hard to count in the daylight.
Fri Oct 30 14:12:37 EDT 2009 Duke of Burgundy 1 Did not expect to see this one here!
Fri Oct 30 14:14:53 EDT 2009 Speckled wood 200 A gaggle of butterflies.

Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:r
Species name:zabulon skipper
Count:-1
Comment:lets try this
Sorry, no negative animals allowed.
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:o
Enter name of file to read:thisfilenamedoesnotexist.dat
ERROR: File thisfilenamedoesnotexist.dat does not exists.
Command list: 

r - enter new Reading
l - List all readings
o - Open file with readings
w - Write readings to a file
q - Quit

Enter command:q
Bye bye.

This homework is due Tuesday, November 10 @noon.

No comments: