Contact
ClassContactList
ClassDue Monday, 4-Sep @ 8:00pm on Gradescope
This assignment will help you refresh your programming abilities and get you a basic introduction to Java. You should start early so that you can attend office hours when problems come up.
For this assignment you have 7 submissions. You should write your own testcases while you work so that you don’t waste submissions. There are some example testcases provided that you can use to get started.
After you have used your submissions, you may continue to submit, but your submission will be penalized 4 points for every extra submission. (So, your 8th submission receives a -4, your 9th submission a -8, etc.)
In this assignment, you’ll build a simple contact list that uses an array-based data structure to grow larger as needed. We’re not writing the next Microsoft Outlook here, but we’ll get a basic contact list up and running.
Download the pre-prepared Eclipse Project hw1.zip
and import it into Eclipse using these instructions. You will make all of your changes inside of Contact.java
, ContactList.java
, and ContactListTester.java
.
Contact
ClassThe Contact
class should represent a single contact. You need to fill in the Contact
class with everything required to store and manage a single contact. You will need relevant instance variables, at least one constructor, and methods (including a toString
).
There are comments inside of Contact.java
to give you some hints.
ContactList
ClassYou will be implementing a simple contact list that grows dynamically to hold more contacts as needed. It also has some methods to manipulate or rearrange those contacts.
You will store the contacts in an array, but arrays in Java have a fixed size defined when they are created. That means that if your array is full and you still need to add another contact to it, you will need to create a new, larger array, copy all of the old contacts to it, and then add your new contact. As a consequence of this, your array may have more “space” available than there are values currently stored. To keep track of which spaces in your array have valid integers and which don’t, you will also be tracking how many contacts are actually stored in the array.
Inside the file ContactList.java
you will find method declarations with empty bodies. You need to implement each incomplete method and write code to test them inside of ContactListTester.java
.
You are free to add new methods to either file (such as helper methods) but do not change the names of any of the provided methods. If you do, you will automatically fail the autograder.
The methods you are writing are as follows:
public boolean isEmpty()
Determines if the ContactList
object is empty or not
true
if there are no contacts in the array, and false
otherwise
public boolean isFull()
Determines if the ContactList
object is full or not
true
if array is full and false
otherwise
private void enlarge()
Optional: A helper function you should consider writing. If the ContactList is currently full, then resize it to be double its current size. To do this, you’ll need to create a new, larger array, and copy the existing items into it.
private int findContact(String id)
Optional: A helper function you should consider writing. Having it might help you with some of the below methods. You can probably figure out what it should do…
public boolean addContact(String andrewId, String firstName, String lastName, String phone)
Add a contact to the contact list. Verify that the new Contact has a unique andrew ID and, if so, add the contact after the current last element, updating numContacts
appropriately.
andrewId
— The andrewId of the contactfirstName
— The firstname of the contactlastName
— The lastname of the contactphone
— The phone number of the contact
public boolean insertContactAtLocation(int loc, String andrewId, String firstName, String lastName, String phone)
Adds a new contact to the contact list, making sure it is at location loc
of the array. This does not replace an entry in the contact list, instead, it inserts the new contact into that location, shifting other contacts as needed.
Only insert the new contact if there are no existing contacts with the same andrew ID already in the contact list and the loc
argument is reasonable. (You can’t, for example, insert at a negative index or insert at an index that would leave gaps in the array.)
e.g., If the array contained [nkuwari, awaatif, jpritch] and this method was called to insert kfrank, then the array would contain [kfrank, nkuwari, awaatif, jpritch].
If the array is full before inserting, you should resize it first to be double its current size.
Don’t forget to update the instance variable that tracks how many items are stored in the array.
loc
— The index where the new contact should be in the arrayandrewId
— The andrewId of the contactfirstName
— The firstname of the contactlastName
— The lastname of the contactphone
— The phone number of the contact
public void removeContact(String id)
Remove a contact from the contact list. If there is no contact with the requested andrewId 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.
id
— The andrewId of the contact to remove
public boolean changePhone(String id, String newNumber)
Change the phone number of a contact.
id
— The andrewId of the contact whose phone number should be
changed
newNumber
— The new phone number
public void rotateLeft()
Rotates all the elements in the contact list one position to the left, placing the first element into the last position.
For example: if the contact list before the call to rotateLeft is [kfrank, nkuwari, awaatif, jpritch] it is [nkuwari, awaatif, jpritch, kfrank] after the call
public void reverse()
Reverses the elements stored in the array
For example: if the array before the call to reverse is [nkuwari, awaatif, jpritch, kfrank] it is [kfrank, jpritch, awaatif, nkuwari] after the call
Your submission will be graded as follows:
For the first 90 points, your submission will be auto-graded on Gradescope.
For the next 5 points, your submission will be manually graded to check for good implementation methodologies. (Did you use a good approach to solving the problems?)
For the next 5 points, your submission will be manually graded to check for good testcases that you include in ContactListTester.java
. (Do you have 2-3 of your own testcases for each method, and do they all execute automatically?) There are two testcases already included to serve as examples.
Your code will also be checked for style. The parts of style that can be checked automatically (things like spacing, indentation, the use of CamelCase, etc.) are automatically checked by the autograder. Other parts of style, such as choosing good variable names, will be checked manually. Autograded style guide violations can result in, at most, -10 points. Manually checked style guide violations can result in, at most, -5 points.
You will submit your program to Gradescope. Log in to the system and you will see the homework. Once there, you need to submit a zip
file containing your code. Lucky for you, however, Eclipse can create this zip file for you. Look at these instructions for exporting. On Gradescope, you’ll submit that exported zip
file. On the page that follows your submission, you will see your live score (out of 90). It may take up to a few minutes for your score to appear. If you receive a lower score than you expect, you can click on the individual testcases to see the feedback from the autograder.
You must follow the model of our testcases from previous assignments (meaning you print when you start, print the results (pass/fail) when you finish, etc.) Additionally, you must comment each testcase with a note describing what it tests.
You may only use the following Java libraries in this assignment:
java.util.Random
java.util.Scanner
java.io.FileReader
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 course staff, and not to the entire class.
Do not change the names of any of the provided methods.
After you submit to Gradescope, make sure you check your score. If you aren’t sure how to do this, then ask.
There is no partial credit on Gradescope testcases. Your Gradescope score is your Gradescope score.
Read the last bullet point again. Seriously, we won’t go back later and increase your Gradescope score for any reason. Even if you worked really hard and it was only a minor error…
You can submit to Gradescope multiple times. So, after you submit you should check your score. If it isn’t a 90 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!
The style guide has a bunch of small rules with regard to indentation and spacing that are hard to follow perfectly. Luckily, Eclipse can handle it for you! Go to Source -> Format
in Eclipse and watch all of your spacing and indentation problems get fixed automatically. (You should do this before every submission.)
Don’t forget to write your own testcases in the appropriate file. We’ll be taking a look at those!