0% found this document useful (0 votes)
159 views12 pages

Phone Directory Application Using Java

Uploaded by

aathiyaeservice
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
159 views12 pages

Phone Directory Application Using Java

Uploaded by

aathiyaeservice
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

PHONE DIRECTORY

APPLICATION USING JAVA


PROJECT REPORT

BY
S.Siva Guru-95072314107
M.P.Siva Surendhar-95072314108
R.Sree Nithin-95072314110
S.L.Subramani-95072314114
Abstract
The Phone Directory Application is a simple console-based program developed
in Java, designed to manage and organize contact information efficiently. The
application allows users to perform essential operations, including adding new
contacts, viewing existing contacts, searching for specific contacts, and deleting
contacts from the directory.
Utilizing an ArrayList to store Contact objects, the application provides an
intuitive menu-driven interface that facilitates easy interaction. Users can input
contact details, and the program dynamically updates the directory. The search
functionality allows quick retrieval of contact information by name, while the
deletion feature ensures that users can manage their contacts effectively.
This project serves as a foundational example of object-oriented programming
principles in Java, demonstrating the use of classes, encapsulation, and basic
data management techniques. It also offers opportunities for future
enhancements, such as data persistence through file storage, input validation,
and the potential development of a graphical user interface (GUI) for improved
user experience. Overall, the Phone Directory Application exemplifies a
practical approach to organizing personal information in a digital format.

Introduction
In an increasingly digital world, effective contact management has become vital
for personal and professional success. The Phone Directory Application is
designed to meet this need by providing a simple, efficient tool for storing and
organizing contact information. Developed using Java, this application allows
users to easily manage their contacts through a console-based interface.
With essential features like adding, viewing, searching, and deleting contacts,
the application simplifies the process of maintaining an organized contact list. It
employs an ArrayList to store contact details, showcasing fundamental
concepts of object-oriented programming, such as encapsulation and class
design.
The user-friendly menu guides users through various functions, ensuring a
seamless experience. As users interact with the application, they can quickly
retrieve or modify information, making it a practical solution for everyday
needs.
This project not only serves as a valuable tool for users but also offers a robust
learning platform for aspiring developers. It lays the groundwork for future
enhancements, such as integrating file storage for data persistence and
exploring graphical user interfaces (GUIs). Ultimately, the Phone Directory
Application exemplifies a functional approach to contact management, making
it an essential resource in today's interconnected environment.

Methodology
The development of the Phone Directory Application follows a structured
methodology that encompasses several key phases. Initially, a thorough
requirement analysis is conducted to identify essential features such as adding,
viewing, searching, and deleting contacts. This is followed by the design phase,
where the application's architecture is outlined, including the creation of the
Contact class and the main application class, PhoneDirectory. A simple text-
based user interface is also designed to facilitate navigation. The
implementation phase involves coding the application in Java, utilizing an
ArrayList for dynamic contact storage and writing methods for each
functionality. After coding, rigorous testing is performed, including unit and
integration tests, to ensure all components function as intended. User testing is
also conducted to gather feedback on usability. Comprehensive documentation
is created to outline features, provide installation instructions, and enhance
code readability. Finally, the application is prepared for deployment, ensuring
that users have the necessary environment to run it successfully. Future
enhancements are identified based on user feedback, which may include data
persistence, input validation, and the development of a graphical user interface
(GUI). This structured approach ensures a high-quality, user-friendly application
while laying the groundwork for potential improvements.
Code

import java.util.ArrayList;
import java.util.Scanner;

class Contact {
String name;
String phoneNumber;

Contact(String name, String phoneNumber) {


this.name = name;
this.phoneNumber = phoneNumber;
}

@Override
public String toString() {
return "Name: " + name + ", Phone Number: " + phoneNumber;
}
}

public class PhoneDirectory {


private ArrayList<Contact> contacts;
private Scanner scanner;

public PhoneDirectory() {
contacts = new ArrayList<>();
scanner = new Scanner(System.in);
}

public void addContact() {


System.out.print("Enter name: ");
String name = scanner.nextLine();
System.out.print("Enter phone number: ");
String phoneNumber = scanner.nextLine();
contacts.add(new Contact(name, phoneNumber));
System.out.println("Contact added.");
}

public void viewContacts() {


if (contacts.isEmpty()) {
System.out.println("No contacts available.");
return;
}
for (Contact contact : contacts) {
System.out.println(contact);
}
}

public void searchContact() {


System.out.print("Enter name to search: ");
String name = scanner.nextLine();
boolean found = false;
for (Contact contact : contacts) {
if (contact.name.equalsIgnoreCase(name)) {
System.out.println(contact);
found = true;
break;
}
}
if (!found) {
System.out.println("Contact not found.");
}
}

public void deleteContact() {


System.out.print("Enter name to delete: ");
String name = scanner.nextLine();
boolean removed = contacts.removeIf(contact ->
contact.name.equalsIgnoreCase(name));
if (removed) {
System.out.println("Contact deleted.");
} else {
System.out.println("Contact not found.");
}
}

public void menu() {


while (true) {
System.out.println("\nPhone Directory Menu:");
System.out.println("1. Add Contact");
System.out.println("2. View Contacts");
System.out.println("3. Search Contact");
System.out.println("4. Delete Contact");
System.out.println("5. Exit");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine(); // consume the newline

switch (choice) {
case 1:
addContact();
break;
case 2:
viewContacts();
break;
case 3:
searchContact();
break;
case 4:
deleteContact();
break;
case 5:
System.out.println("Exiting...");
return;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}

public static void main(String[] args) {


PhoneDirectory phoneDirectory = new PhoneDirectory();
phoneDirectory.menu();
}
}

Explaination

The Phone Directory Application is structured around a main PhoneDirectory


class that manages contact information through an ArrayList of Contact objects.
Each Contact consists of a name and a phone number, with a method to
provide a readable string representation. The application features a menu-
driven interface that allows users to perform key operations: adding contacts,
viewing all contacts, searching for specific contacts, and deleting contacts.
When a user chooses to add a contact, they are prompted for a name and
phone number, which are then stored in the list. The viewing function checks if
the list is empty and displays all contacts if not. The search function allows for
case-insensitive matching, returning the contact if found. The delete function
removes a contact by name and informs the user of the result. The menu
method provides a loop for user interaction, enabling continuous operation
until the user decides to exit. Overall, the application is designed to be simple
and intuitive, demonstrating fundamental programming concepts while
allowing room for future enhancements, such as data persistence and a
graphical user interface.
Output
Phone Directory Menu:
1. Add Contact
2. View Contacts
3. Search Contact
4. Delete Contact
5. Exit
Choose an option: 1
Enter name: Alice
Enter phone number: 123-456-7890
Contact added.

Phone Directory Menu:


1. Add Contact
2. View Contacts
3. Search Contact
4. Delete Contact
5. Exit
Choose an option: 1
Enter name: Bob
Enter phone number: 987-654-3210
Contact added.

Phone Directory Menu:


1. Add Contact
2. View Contacts
3. Search Contact
4. Delete Contact
5. Exit
Choose an option: 2
Name: Alice, Phone Number: 123-456-7890
Name: Bob, Phone Number: 987-654-3210

Phone Directory Menu:


1. Add Contact
2. View Contacts
3. Search Contact
4. Delete Contact
5. Exit
Choose an option: 3
Enter name to search: Alice
Name: Alice, Phone Number: 123-456-7890

Phone Directory Menu:


1. Add Contact
2. View Contacts
3. Search Contact
4. Delete Contact
5. Exit
Choose an option: 4
Enter name to delete: Bob
Contact deleted.

Phone Directory Menu:


1. Add Contact
2. View Contacts
3. Search Contact
4. Delete Contact
5. Exit
Choose an option: 2
Name: Alice, Phone Number: 123-456-7890

Phone Directory Menu:


1. Add Contact
2. View Contacts
3. Search Contact
4. Delete Contact
5. Exit
Choose an option: 5
Exiting...

Future Enhancement

Future enhancements for the Phone Directory Application can significantly


improve its functionality and user experience. One key improvement is the
implementation of data persistence, allowing contacts to be saved to a file
(such as CSV or JSON) and loaded upon startup, ensuring information is
retained between sessions. Adding input validation would enhance robustness
by checking that phone numbers are formatted correctly and that names are
not empty. Transitioning to a graphical user interface (GUI) using JavaFX or
Swing would create a more interactive and visually appealing experience,
making navigation easier for users. Additionally, enhancing the search
functionality to allow partial matches and sorting contacts alphabetically would
improve usability. Introducing contact groups for better organization and
developing a mobile version of the application could cater to users on the go.
Cloud storage integration would enable backup and access across devices,
while multi-language support would broaden the application's accessibility.
Advanced search filters and comprehensive unit testing could further refine the
application's reliability and performance. Overall, these enhancements would
align the application with contemporary software standards and meet evolving
user expectations.

Conclusion

The Phone Directory Application serves as a practical and effective tool for
managing contact information, demonstrating fundamental programming
principles and providing a user-friendly experience. Through its core
functionalities—adding, viewing, searching, and deleting contacts—the
application meets essential user needs while showcasing the use of object-
oriented programming in Java. The structured approach to development
ensures that the application is not only functional but also maintainable and
scalable for future enhancements. By considering improvements such as data
persistence, a graphical user interface, and advanced search features, the
application can evolve to meet the growing demands of users. Ultimately, the
Phone Directory Application stands as a solid foundation for further
development, offering valuable insights into software design and user
interaction, while remaining a relevant tool in today’s digital landscape.

You might also like