The driver class should have a main menu that includes at least the following choices.
1. Import contacts from a file
2. Create and add a new Contact to AddressBook
3. Edit an existing Contact and update the AddressBook
4. Remove a Contact from the AddressBook by name
5. Display all Contacts from the AddressBook
6. Find and display a Contact by name in the AddressBook
7. Display all Contacts of a given ContactType
8. Display all Contacts that are in a specified zip code
9. Sort the Contacts in the AddressBook by name
10. Exit
The AddressBook class should have at least the following private attributes, but you may add as many others as needed:
* ArrayList <Contact>
* A special Contact named owner that represents the individual owner of the AddressBook. This will be the user of the program who gives his/her name when welcomed to the program.
In addition to the usual constructors, getters, setters, and toString methods, the AddressBook class will need the methods required to support the functionality required in the driver (searching, sorting, retrieving a Contact, adding a Contact, and so forth).
Note: The AddressBook class contains a PRIVATE ArrayList<Contact>. Since the ArrayList is private, its methods are NOT ACCESSIBLE from the driver or any other class. You will need to add public methods such as get, set, size, and remove to AddressBook class so they can be used from outside of AddressBook to access the necessary features of the encapsulated ArrayList.
Test the program with at least 10 Contact objects of varying ContactTypes. Otherwise, you will not be assured that all sorting and searching methods have been completely tested. This information should be in a txt file that can be read in by the driver if that option is chosen. The user must be able to choose the file to be read in (using JFileChooser). If the contacts have been changed in any way, you are to write out the updated address book to a file (again using JFileChooser) before the program closes. In your design document, be sure to provide the complete list of Contact information to be used in testing.
You must handle all exceptions in processing. Simply adding a throws Exception clause to the methods inside the driver does not count as “handling the exceptions”.
Carey Brown wrote:Cross posted on
http://stackoverflow.com/questions/27311909/read-and-add-text-file-to-an-arraylist-of-object-in-java
Cross posting is acceptable on CodeRanch but you should be up front about it so that people don't duplicate effort.
Nikki Smith wrote:
Carey Brown wrote:Cross posted on
http://stackoverflow.com/questions/27311909/read-and-add-text-file-to-an-arraylist-of-object-in-java
Cross posting is acceptable on CodeRanch but you should be up front about it so that people don't duplicate effort.
Cross post? What are you talking about? That isn't my post if that's what you meant, unless you simply mean that it's a similar question, however I did search around to try to puzzle some of this out on my own, but with little success. I didn't even see that stack post you mentioned. Actually that post on stack looks like its from 2014.
Nikki Smith wrote:I would have to have such logic inside of each case statement to call to the appropriate methods as I'm not sure how else to go about this given the limitations of only having the four classes to work with. That makes me cringe...
Nikki Smith wrote:I have a method that can read the contents of the file and assemble each line into an ArrayList of type String since there's really no way of knowing how many contacts a file could actually contain. So once each line is stored into an array list then I need to use another method to somehow take each item from that ArrayList and split at a delimiting pipe space character in the text file
and then somehow pass each piece of information into the contact class constructor. I have no idea how to even go about passing an array of strings to the Contact class to be made into a Contact object and especially since one value that will be read in from the file is an Enum. Maybe I could use valueOf, but I'm not sure. Without hard coding all 9 indexes of the array of delimited strings into a call to the Contact constructor, how else might I pass the array of string data to the constructor, while also being mindful of the one Enum that would have to be dealt with as well?
Junilu Lacar wrote:Do you really need to do it that way? I'd argue that you can do it that way but there's no need to make it so complicated. You have to set your foot down as to what the arrangement of the data in the text file should be. Otherwise, there's no limit to the number of variations you're going to have to contend with in your program. A common format to use is CSV (comma-separated values) with one line in the text file representing the data for one record, which is in this case is one contact. Each line must consistently have the same order of data elements. You decide what that order is and write your program accordingly.
Once you have that decision firmed up, then you can simply read each line in with a Scanner. You can then scan each line for the data items.
where the parseContactInfo() will use another scanner to read in each separate Contact field and populate a new Contact instance with that information.
Do you see how I'd break the task down to smaller, more manageable chunks again?
Other|Bill Nye|4742 42nd Avenue|Seattle|WA|98116|2067159824|[email protected]|SmartGuy.jpg
All things are lawful, but not all things are profitable.
Knute Snortum wrote:Are the field separated by a literal pipe character (|)? If so, try using String#split(regex). The only tricky thing about that is that in a regex, the pipe character is a "metacharacter". That means you'll have to escape it.
All things are lawful, but not all things are profitable.
Nikki Smith wrote:
Knute Snortum wrote:Are the field separated by a literal pipe character (|)? If so, try using String#split(regex). The only tricky thing about that is that in a regex, the pipe character is a "metacharacter". That means you'll have to escape it.
The class hasn't learned regex, so I doubt I'd be allowed to use it. Technically they don't even mention Regex until higher level courses.
I am not a spy. Definitely. Definitely not a spy. Not me. No way. But this tiny ad ...
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
|