Share on Google+Share on Google+

java source code
2 Answer(s)      6 years and 9 months ago
Posted in : Java Beginners
hello Sir,
Im a beginner in greatly confused, so plz send me the source code for the following concept:

Telephone directory management system:

Accept the ID, name, residential address and phone number for N subscribers and perform the following operations :
1. Search for an input name and print their address and phone number.
2. Sort the records in the ascending order of the ID.
3. Print a report listing all subscribers with their details in a tabular form.


View Answers

July 26, 2010 at 1:06 PM

Hi Friend,

Try the following code:

import java.util.*;
class Directory implements Comparable{
int id;
String name;
String address;
int phoneNo;

public int getId(){
return id;
public void setId(int id){;

public String getName(){
return name;
public void setName(String name){;
public String getAddress(){
return address;
public void setAddress(String address){
public int getPhoneNo(){
return phoneNo;
public void setPhoneNo(int phoneNo){

public int compareTo(Object ob) throws ClassCastException {
if (!(ob instanceof Directory))
throw new ClassCastException("Error");
int ide = ((Directory) ob).getId();
return - ide;
public class TelephoneDirectory{

public static void main(String[] args) throws Exception{
Scanner scan = new Scanner(;
int menu = 0;
System.out.println("Telephone Directory Management System");
System.out.println("1. Accept Data");
System.out.println("2. Search");
System.out.println("3. Sort Data");
System.out.println("4. List of all persons");
System.out.println("5. Exit");
boolean quit = false;
System.out.print("Please enter your choice: ");
menu = scan.nextInt();

case 1:
System.out.print("Enter student ID: ");
int ID = scan.nextInt();
System.out.print("Enter Name: ");
String name=;
System.out.print("Enter Address: ");
System.out.println("Enter Phone No: ");
int no=scan.nextInt();
FileWriter fw = new FileWriter(new File("directory.txt"),true);
BufferedWriter out = new BufferedWriter(fw);
out.write(ID+" "+name+" "+address+" "+no);
case 2:
System.out.print("Enter name to search information: ");
File f = new File("directory.txt");
try {
BufferedReader freader = new BufferedReader(new FileReader(f));
String s;
while ((s = freader.readLine()) != null) {
String[] st = s.split(" ");
String id = st[0];
String nm = st[1];
String add = st[2];
String phoneNo = st[3];
if (n.equals(nm)) {
System.out.println("Address : "+add);
System.out.println("PhoneNo : "+phoneNo);
} catch (Exception e) {

July 26, 2010 at 1:07 PM


case 3:
File file = new File("directory.txt");
FileInputStream fstream = new FileInputStream(file);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader( new InputStreamReader(in));
String strLine;
ArrayList list = new ArrayList();
while ((strLine = br.readLine()) != null) {
int j = 0;
Directory data[] = new Directory[list.size()];
try {
Iterator itr;
for (itr = list.iterator(); itr.hasNext();) {
String str =;
String[] splitSt = str.split(" ");
String id = "", nn = "", add = "", pno = "";
for (int i = 0; i < splitSt.length; i++) {
id = splitSt[0];
nn = splitSt[1];
add = splitSt[2];
pno = splitSt[3];

data[j] = new Directory();


BufferedWriter bw = new BufferedWriter(new FileWriter(file,true));
System.out.println("********Sorted by id********");
String strVal = "";
for (int i = 0; i < 8; i++) {
Directory show = data[i];
int ide = show.getId();
String nnn = show.getName();
String add = show.getAddress();
int phone = show.getPhoneNo();
System.out.println(ide+" "+nnn+" "+add+" "+phone);
} catch (Exception e) {

case 4:

FileInputStream fis = new FileInputStream( new File("directory.txt"));
DataInputStream dis = new DataInputStream(fis);
BufferedReader reader = new BufferedReader( new InputStreamReader(dis));
String st;
ArrayList al = new ArrayList();
while ((st = reader.readLine()) != null) {
Iterator itr;
for (itr=al.iterator(); itr.hasNext(); ){
String [] splitSt =str.split(" ");
String id="",na="",ada="",ph="";
for (int i = 0 ; i < splitSt.length ; i++) {
System.out.println(id+" "+na+" "+ada+" "+ph);
case 5:
quit = true;
System.out.println("Invalid Entry!");
while (!quit);


Related Tutorials/Questions & Answers:
Java source code
Java source code  How are Java source code files named
java source code
java source code  java source code to create mail server using struts2
request for java source code
request for java source code  I need source code for graphical password using cued-click points enabled with sound signature in java and oracle 9i as soon as possible... Plz send to my mail
Java Source code
Java Source Code for text chat application using jsp and servlets  Code for text chat application using jsp and servlets
Source Code - Java Beginners
Source Code  What do I have to add to my original code to make it work
Source Code - Java Beginners
Source Code  How to clear screen on command line coding like cls in DOS?  Hi Friend, Here is the code to execute cls command of DOS through the java file but only one restriction is that it will execute
source code - Java Beginners
source code  Hi...i`m new in java..please help me to write program that stores the following numbers in an array named price: 9.92, 6.32, 12,63... message dialog box.  Hi Friend, Try the following code: import
source code of java
source code of java  how to create an application using applets is front end and back end is sqlwith jdbc application is enter the student details and teaching & non teaching staff details and front end is enter in internet
java source code - Java Beginners
java source code  I have written a source code for recording invoices. I wish it to be evaluated. Could somebody help me with it? Moreover, I do not know the method to attach the JAR for evaluation. My email
Java Source code - Java Beginners
Java Source code  Write a Multi-user chat server and client
java source code - Java Beginners
java source code  write a program to read the value of n as total number of friend relatives to whom the person wants to call
Java source code - Java Beginners
Java source code  Write a small record management application for a school. Tasks will be Add Record, Edit Record, Delete Record, List Records. Each Record contains: Name(max 100 char), Age, Notes(No Maximum Limit). No database
source code program - Java Beginners
source code program  I need the source code for a program that converts temperatures from celsius to fahrenheit and vice versa, as well as converting kilometers to miles and vice versa using Java "classes".  Hi
java source code - Java Beginners
java source code  hello Sir, Im a beginner in greatly confused, so plz send me the source code for the following concept: Telephone... code: import*; import java.util.*; class Directory implements
Need Java Source Code - JDBC
Need Java Source Code  I have a textfield for EmployeeId in which the Id, for eg: "E001" has to be generated automatically when ever i click... be implemented.  Hi friend, Please send me code because your posted
Source Code cls - Java Beginners
Source Code cls   Dear RoseIndia Team, Thanks for your prompt reply to my question about alternate to cls of dos on command line source code. I have two submissions. 1. Instead of three lines if we simply write
calendra.css source code - Java Beginners
calendra.css source code  hello i need the source code... and year are getting displayed  Hi Friend, Try the following code...; cursor: pointer; } You can also download the code from the following link
online shopping project report with source code in java
online shopping project report with source code in java  Dear Sir/Mam, i want to a project in java with source code and report project name online shopping. thank you
online voting system source code in java
online voting system source code in java  Please send me source code for online voting system in java. please replay as fast as. Thank you
Source code
Source code  source code of html to create a user login page
download java source code for offline referral
download java source code for offline referral   how can i download complete java tutorial from rose india so that i can refer them offline
View source code of a html page using java ..
View source code of a html page using java ..  I could find the html source code of a web page using the following program, i could get the html code
Screen scrapper tool java source code
Screen scrapper tool java source code  From where can i dload the souce code for this screen scrapper tool ? Please let me know. Thanks
source code
source code  sir...i need an online shopping web application on struts and jdbc....could u pls send me the source code
source code
source code  sir...i need an online shopping web application on struts and jdbc....could u pls send me the source code
source code
source code  hellow!i am developing a web portal in which i need to set dialy,weekly,monthly reminers so please give me source code in jsp
source code
source code  how to use nested for to print char in java language?   Hello Friend, Try the following code: class UseNestedLoops{ public static void main(String[] args){ char[][] letters = { {'A', 'B'}, {'C','D
Problem with Java Source Code - Java Beginners
Problem with Java Source Code  Dear Sir I have Following Source Code ,But There is Problem with classes, plz Help Me. package mes.gui; import javax.swing.JOptionPane.*; import java.sql.*; import javax.swing.*; import
source code - Java Server Faces Questions
source code  hi deepak i need a program's source code in javascript which will response to mouse event. with description of onmouseout nd onmouseover... waiting 4 ur reply   Hi friend, Code for onmouseout nd
source code
source code  how to get the fields from one page to another page in struts by using JSTL
java source code to create mail server using struts2
java source code to create mail server using struts2  java source code to create mail server using struts2
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized


Advertisement null