COMP 120 – Problem Solving Assignment 2

1. The program should maintain the address list as a Python list. (The choice of a list
becomes the natural choice after seeing the behavior of the buttons in the window.)
2. Each entry in the address list should be an object of type Address. So you need to
define a class called Address that encapsulates (with instance variables) the name,
street, city, state, and zip of a single address. The Address class should be defined in
the same file as the AddressBook class.
3. The “First” button displays the first address in the address list. The address is
displayed in the entry name, street, city, state, and zip fields. So the entry fields
double as display fields. If there is no first address (the address list is empty), the
button should not do anything.
4. The “Next” button displays the next address in the address list (the next address
after the one currently being displayed). This suggests that the program should
keep track of the index of the address currently being displayed. If there is no next
address (the last address is already being displayed, or the list is empty), the button
should not do anything.
5. The “Previous” button should display the previous address in the address list. If
there is no previous address, the button should not do anything.
6. The “Last” button should display the last address in the address list. If there is no
last address (the list is empty), the button should do nothing.
7. If an address is displayed in the entry fields, the user can edit it in any way they
want, and then add that address to the address book by hitting the “Add” button.
The address should be added directly after the current address that is being
displayed. If there is no current address (because the list is empty), then the added
address should go at the beginning of the list. After an add, the newly added address
should become the current address being displayed.
8. If the user hits the “Delete” button, the currently displayed address should be
deleted from the address list. If there is no currently displayed address (because the
list is empty), the button should not do anything. After an address is deleted, the
currently displayed address should be the address after the deleted address, and if
there is not next address, the previous address, and if there is also no previous
address (because the list is now empty), nothing should be displayed.
9. The user can load an address list from a file by entering a filename in the “Filename”
entry field, and hitting the “Load File” button. If the filename entry field is empty, or
if the file cannot be opened, then the button should not do anything. If the file can
be opened, the current address list should be deleted, and replaced by the contents
of the file. The format of the file is illustrated by the sample file in the repository. (5
lines for each address – one line for each field of the address.) You can assume that
an address file has the correct format, so you do not have to do any exception
handling while reading the file. After reading in a file, the current address should be
the first address that was read in from the file.
10. The user can store an address list to a file by entering a filename in the “Filename”
entry field, and hitting the “Save to File” button. If the filename entry field is empty,
or if the file cannot be opened, then the button should not do anything. If the file can
be opened, the current address list should be written to the file. The format of the
file is illustrated by the sample file in the repository. (5 lines for each address – one
line for each field of the address.)
11. All of your code must be written in the AddressBook class, and the Address class.
(The Address class should be very short – it is just a holding place for the 5 fields of
an address.)
12. Use descriptive variable names in your program, and use all lowercase letters with
underscores separating words. You should appropriately comment your program. It
should have a header (this is started for you – be sure to add your names, the date
you started it, and a description); each function should have docstring comments.
13. You should also comment blocks of code within your functions, explaining what the
code is doing. How much commenting to add is a judgement call – you don’t want too
much, or too little. If you have a block of code (say up to 10 lines long), put a brief
comment before it saying what is about to happen. Then put blank lines between the
blocks of code. Don’t comment individual lines of code, unless they are doing
something that the reader might not see right away.

DETAILED ASSIGNMENT

20200917185427comp120_sp20_psa2

Powered by WordPress