Project Program: write PSEUDOCODE to design a phone contact list program. PSEUDO
ID: 3918437 • Letter: P
Question
Project Program: write PSEUDOCODE to design a phone contact list program. PSEUDOCODE is the made up computer language used in STARTING OUT WITH PROGRAMMING LOGIC AND DESIGN by TONY GADDIS. If pseudocode is unavailable, generic coding or anything to solve parts of the program will help!! Your program includes a Graphical User Interface that allows user to add new contacts, update existing contacts, search specific contact from the contact list, sort the contact list in ascending or descending order, delete an old contact. Your program should also provide help screen, an exit button to close the program and displays error messages for any exceptions.
Please apply what you learn from these chapters in designing your program: ? Chapter 9 Sorting ? Chapter 10 Files (open file for writing data, open file for reading data etc) ? Chapter 11 Menu-Driven Programs (add, update, search/sort, delete, help, exit, Error etc.) ? Chapter 14 OOP: Object-Oriented design ( class, object, methods) ? Chapter 15 GUI (main menu, sub menu)
Input: ? Write a data text file with a list of phone number (10 digits with dashes, 555-555-5555) ? Read text file to retrieve contact info (phone number, first name, last name) o Read the file into memory (hint: parallel arrays) ? Individual contact info can also be entered from the keypad
Process: (open/read the file, display the menu, close file) ? Maintain the phone list by ADD, UPDATE, DELETE, INQUIRE/SEARCH, SORTING o When each item on the menu is done, redisplay the menu
Output: (per each navigation menu item)
? Design a GUI screen that include o Keypad with numbers o Navigation menu ? Add New Contact ( textbox for first name, last name, textbox for phone number) ? Update Contact (search by phone number to display name and phone OR search by name to display name and phone number) ? Delete Contact from List (change name to blank) ? Inquire: enter phone name or name ? List: Sort list either ascending or descending order by first name or last name ? Help ? Save phone list ? Exit
? Define a CONTACT class o Fields (phone number, first name, last name) o Set & get method o Constructor o Methods (add, update, delete, save, sort, display the list etc. )
? Object: personal contact list Or company phone directory (inheritance) o Public class PersonalContact extends Contact { }
Add: Enter phone number (phone number: range 1-999) If not found – display message If name is blank, enter name (first and last) If name NOT blank, save contact info, display confirm message
Change: Enter phone number If not found – display message IF found – display name and ask for new name If name is blank, ask for new name
Delete: Enter phone number If not found – display message If found – display name and confirm delete If confirm is yes – blank out name If confirm is no – return to menu If name is blank, display message
Inquire: Enter phone number If found – display name If not found – display message If found and name is blank – display message
Sort: Question: sort ascending, descending or return to menu If return to menu, then return to menu If ascending- sort phone number ascending If descending - sort phone number in descending order After sort, display phone list
Help:Display menu option and a one description of the function
Save: Write phone list back to file
Exit: If file is open, save phone list, close file Terminate program
Error: If a menu selection is made that is not displayed (1-9) Issue message and display the help screen
THANK YOU!
Explanation / Answer
To add a contact:
// Creates a new Intent to insert a contact
Intent intent = new Intent(Intents.Insert.ACTION);
// Sets the MIME type to match the Contacts Provider
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
The function:
public static void Insert2Contacts(Context ctx, String nameSurname,
String telephone) {
if (!isTheNumberExistsinContacts(ctx, telephone)) {
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
int rawContactInsertIndex = ops.size();
ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
.withValue(RawContacts.ACCOUNT_TYPE, null)
.withValue(RawContacts.ACCOUNT_NAME, null).build());
ops.add(ContentProviderOperation
.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(
ContactsContract.Data.RAW_CONTACT_ID,
rawContactInsertIndex)
.withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
.withValue(Phone.NUMBER, telephone).build());
ops.add(ContentProviderOperation
.newInsert(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID,
rawContactInsertIndex)
.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
.withValue(StructuredName.DISPLAY_NAME, nameSurname)
.build());
try {
ContentProviderResult[] res = ctx.getContentResolver()
.applyBatch(ContactsContract.AUTHORITY, ops);
} catch (Exception e) {
Log.d(TAG, e.getMessage());
}
}
}
To change a contact:
// Creates a new Intent to insert or edit a contact
Intent intentInsertEdit = new Intent(Intent.ACTION_INSERT_OR_EDIT);
// Sets the MIME type
intentInsertEdit.setType(Contacts.CONTENT_ITEM_TYPE);
// Add code here to insert extended data, if desired
To search a contact:
public static boolean isTheNumberExistsinContacts(Context ctx,
String phoneNumber) {
Cursor cur = null;
ContentResolver cr = null;
try {
cr = ctx.getContentResolver();
} catch (Exception ex) {
Log.d(TAG, ex.getMessage());
}
try {
cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null,
null, null);
} catch (Exception ex) {
Log.i(TAG, ex.getMessage());
}
try {
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(cur
.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur
.getString(cur
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
// Log.i("Names", name);
if (Integer
.parseInt(cur.getString(cur
.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
// Query phone here. Covered next
Cursor phones = ctx
.getContentResolver()
.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID
+ " = " + id, null, null);
while (phones.moveToNext()) {
String phoneNumberX = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
// Log.i("Number", phoneNumber);
phoneNumberX = phoneNumberX.replace(" ", "");
phoneNumberX = phoneNumberX.replace("(", "");
phoneNumberX = phoneNumberX.replace(")", "");
if (phoneNumberX.contains(phoneNumber)) {
phones.close();
return true;
}
}
phones.close();
}
}
}
} catch (Exception ex) {
Log.i(TAG, ex.getMessage());
}
return false;
}
To delete a contact:
public static boolean deleteContact(Context ctx,String phoneNumber) {
Uri contactUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(phoneNumber));
Cursor cur = ctx.getContentResolver().query(contactUri, null, null,
null, null);
try {
if (cur.moveToFirst()) {
do {
String lookupKey =
cur.getString(cur.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Uri uri = Uri.withAppendedPath(
ContactsContract.Contacts.CONTENT_LOOKUP_URI,
lookupKey);
ctx.getContentResolver().delete(uri, null, null);
} while (cur.moveToNext());
}
} catch (Exception e) {
System.out.println(e.getStackTrace());
}
return false;
}
}
To get help:
public void help{
System.out.println(“Menu Options:”);
System.out.println
an old contact.”);
System.out.println(“4.search specific contact from the contact list”);
System.out.println(“5.sort the contact list in ascending or descending order”);
System.out.println(“6.help sc(“1.add new contacts”);
System.out.println(“2.update existing contacts”);
System.out.println(“3.delete reen”);
System.out.println(“7.save”);
System.out.println(“8.exit”);
}
To display error:
public void error{
System.out.println(“Invalid input, error”);
help();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.