Homework 2: Contact List
Due September 24 @ 8:00pm on Autolab
In this assignment you’ll build a simple contact list, using data in names.txt
as an initial dataset. We’re not writing the next Microsoft Outlook here, but we’ll get a basic contact list up and running.
Download a pre-prepared Eclipse Project hw2.zip
and import it into Eclipse using these instructions. You will make all of your changes inside of Contacts.java
and Contact.java
.
Your Tasks
You will need to write the following items:
Contact
Class
You need to fill-in theContact
class with everything required to store and manage a single contact. You will need relevant instance variables, at least one constructor, and methods (including atoString
). The design of the object is up to you.Contacts(String filename)
(Constructor in Contacts.java)
This constructor takes a filename (a String), opens the file, and assuming it is openable, loads the contacts array with data from the file. While doing this, it needs to ensure that the contact list does not contain any entries with duplicate andrew IDs. If the file contains two or more entries with the same andrew ID, only the first one should be added to the contact list.void removeContact(String id)
Removes the entry for the contact with andrew ID,id
, from the contact list, if it exists. If there is no contact with the andrew ID then this method should do nothing. When removing the contact, other contacts in the array will need to be shifted to ensure there are no “gaps” in the array.boolean addContact(String firstName, String lastName, String andrewId, String phone, String group1, String group2)
Add a contact to the Contact list. If there is room in the contacts array, verify that the new Contact has a unique andrew ID and, if so, add the contact after the current last element, updatingnumContacts
appropriately, and returntrue
. Otherwise, returnfalse
.void changePhone(String id, String newNumber)
If a contact with andrew ID,id
, exists, change the phone number that belongs to the contact with that ID tonewNumber
.String[] allInGroup(String g)
Returns an array containing all the andrew IDs for contacts in the contact list that are in the specified group,g
. The array should be exact size of the number of andrew IDs it contains.void updateDatabase(String filename)
Creates a file with name provided byfileName
and writes the contents of the contact list to this file. The file should follow the same file format as the input file. Your file must be written so that it can be read back in by your program.
Note: When testing this, you will quickly discover that Eclipse doesn’t automatically show you new files that appear in a project. To force Eclipse to update the list of files in a project, right-click on the project and choose “Refresh”.
File Format
The input (and output) files that your program should be able to work with have a comma separated value (CSV) format. Each line the file contains the information for one contact, with each field of that contact separated by a comma. The fields are:
First Name, Last Name, andrew ID, Phone #, Group 1, Group 2
Most of these fields are self explanatory. Group 1 and Group 2 represent contact groups which this contact belongs to.
The provided Eclipse project includes a sample file (names.txt
) that you can use for testing. (Looking at it will also help you make sure you understand the file format.)
Grading and Submission
There are two parts of the grading of this assignment:
- For the first 70 points, your submission will be auto-graded on Autolab.
- For the next 30 points, your submission will be manually graded to check for things like style, implementation methodology, and the testcases you include in the main method.
You will submit your program to Autolab. Login to the system and you will see the homework.
For this homework, because there are two files, you’ll need to submit a zip
file containing your code. Luck for you, however, Eclipse can create this zip file for you. Check out these instructions. On Autolab, you’ll submit that exported zip
file. On the page that follows your submission you will see your live score (out of 70). It may take up to a few minutes for your score to appear, during that time just hit refresh in your browser. If you receive a lower score than you expect, you can click on the score to see the feedback from the autograder.
Important Notes
- It may be helpful for you to write a helper function in the
Contacts
class. Something likefindContact(String id)
that returns the integer index in the array of the contact with the provided andrew ID (or -1 if the ID isn’t found). This helper function could be useful in many other functions… - If you have questions, please post to Piazza. The course staff, including the instructor, monitor and answer questions there.
- When posting to Piazza, if you include any code make sure your question is posted privately to the instructors, and not to the entire class.
- Do not change the names of any of the provided methods or files.
- After you submit to Autolab, make sure you check your score. If you aren’t sure how to do this, then ask.
- There is no partial credit on Autolab testcases. Your Autolab score is your Autolab score.
- Read the last bullet point again. Seriously, we won’t go back later and increase your Autolab score for any reason. Even if you worked really hard and it was only a minor error…
- You can submit to Autolab multiple times. So, after you submit you should check your score. If it isn’t a 70 you can keep working until it is.
- Don’t forget to make sure your code conforms to the style guide. We’ll be taking a look at that!
- Don’t forget to write your own testcases in the
main
method of theContacts
class. We’ll be taking a look at those!