Home Answers Viewqa Java-Beginners java source code

 
 


deepanandakumar
java source code
2 Answer(s)      2 years and 10 months ago
Posted in : Java Beginners

hello Sir,
Im a beginner in java.im 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.io.*;
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){
this.id=id;
}

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

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

public static void main(String[] args) throws Exception{
Scanner scan = new Scanner(System.in);
int menu = 0;
System.out.println("Telephone Directory Management System");
System.out.println();
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;
do{
System.out.print("Please enter your choice: ");
menu = scan.nextInt();
System.out.println();

switch(menu){
case 1:
System.out.print("Enter student ID: ");
int ID = scan.nextInt();
System.out.print("Enter Name: ");
String name= scan.next();
System.out.print("Enter Address: ");
String address=scan.next();
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);
out.newLine();
out.close();
break;
case 2:
System.out.print("Enter name to search information: ");
String n=scan.next();
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("***********Information**************");
System.out.println("Address : "+add);
System.out.println("PhoneNo : "+phoneNo);
}
}
freader.close();
} catch (Exception e) {
}
break;

July 26, 2010 at 1:07 PM


continue.........

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) {
list.add(strLine);
}
int j = 0;
Directory data[] = new Directory[list.size()];
try {
Iterator itr;
for (itr = list.iterator(); itr.hasNext();) {
String str = itr.next().toString();
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();
data[j].setId(Integer.parseInt(id));
data[j].setName(nn);
data[j].setAddress(add);
data[j].setPhoneNo(Integer.parseInt(pno));

j++;
}

BufferedWriter bw = new BufferedWriter(new FileWriter(file,true));
Arrays.sort(data);
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) {
}
break;

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) {
al.add(st);
}
Iterator itr;
for (itr=al.iterator(); itr.hasNext(); ){
String str=itr.next().toString();
String [] splitSt =str.split(" ");
String id="",na="",ada="",ph="";
for (int i = 0 ; i < splitSt.length ; i++) {
id=splitSt[0];
na=splitSt[1];
ada=splitSt[2];
ph=splitSt[3];
}
System.out.println(id+" "+na+" "+ada+" "+ph);
}
break;
case 5:
quit = true;
break;
default:
System.out.println("Invalid Entry!");
}
}
while (!quit);
}
}

Thanks









Related Pages:
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
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 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
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
Java Source code - Java Beginners
Java Source code  Write a Multi-user chat server and client
reg : the want of source code
reg : the want of source code  Front End -JAVA Back End - MS Access Hello Sir, I want College Student Admission Project in Java with Source code...) Available Seats and etc. plz Give Me Full Source code with Database
source code - JDBC
source code  give me a source code to connect from java to mysql that can run on eclipsed i am using mysql-essential-5.0.41-win32_1. also give procedure how can i connect from eclipsed to mysql-essential-5.0.41-win32_1. thanks
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 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 java.im greatly confused, so plz send me the source code for the following concept: Telephone... code: import java.io.*; 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 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
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
shoping items billng source code
)price.jsp: <%@page language="java" import ="java.sql.*" %> <% String code...shoping items billng source code  Hi, I am doing a project on invoice making, I am unable to make code for the billing, I have a n jsp page "invc.jsp
shoping items billng source code
)price.jsp: <%@page language="java" import ="java.sql.*" %> <% String code...shoping items billng source code  Hi, I am doing a project on invoice making, I am unable to make code for the billing, I have a n jsp page "invc.jsp
shoping items billng source code
)price.jsp: <%@page language="java" import ="java.sql.*" %> <% String code...shoping items billng source code  Hi, I am doing a project on invoice making, I am unable to make code for the billing, I have a n jsp page "invc.jsp
shoping items billng source code
)price.jsp: <%@page language="java" import ="java.sql.*" %> <% String code...shoping items billng source code  Hi, I am doing a project on invoice making, I am unable to make code for the billing, I have a n jsp page "invc.jsp
shoping items billng source code
)price.jsp: <%@page language="java" import ="java.sql.*" %> <% String code...shoping items billng source code  Hi, I am doing a project on invoice making, I am unable to make code for the billing, I have a n jsp page "invc.jsp
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
Need source code - Swing AWT
Need source code  Hai, In java swing, How can upload and retrieve the images from the mysql database?   Hi Friend, To upload and insert image in database, try the following code: import java.sql.*; import
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, http://download.oracle.com/javase/1.4.2/docs/api/java/net/URLConnection.html 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  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
source  how to pass the morethan one fields from one page to another page in struts1.2? i am using tchnologies are struts1.2 oracle 10g myecllipse 8.6 so please post the exact source code to support the above technologies
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
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
source code  how to get the fields from one page to another page in struts by using JSTL
Path of source code
Description:  This example demonstrate how to get the path of your java program file. The URI represents the abstract pathname and URL construct from URI. Code: import java.io.
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
i need attendce management system source code in java
i need attendce management system source code in java  i need attendance management system source code in java
java source code to send group mails using struts2
java source code to send group mails using struts2  code to send group mails using struts2
Source Code for Search Engine Project in java - Java Beginners
Source Code for Search Engine Project in java  Hello Sir ,I want Java Project for Search Engine(like google),How I can Make it,Plz Give Me Complete Source Code Of Search Engine Project in Java.  Hi Friend, Please
source code in java for a program using class - Java Beginners
source code in java for a program using class  Dear sir/madam i want source code in java for following program: WAP which creates a class accountthat stores customer name,account number and type of account.From this derive
provide source - Java Beginners
the files/pages must be stored in a folder.  Hi This is the source code...provide source  please provide code for this program Write a program to download a website from a given URL. It must download all the pages from
source code for the following question
source code for the following question  source code for the fuzzy c-means
B+ tree JAVA source code for implementing Insertion and Deletion - Java Beginners
B+ tree JAVA source code for implementing Insertion and Deletion  Can anyone plz mail de B+ tree JAVA source code for implementing Insertion and Deletion..Its urgent   Hi friend, public class BinarytreeDemo
source code in jsp
source code in jsp  i need the source code for online payment in jsp
Hiding Source Code - WebSevices
Hiding Source Code  Is there any way to prevent viewing source code in browser
java/j2ee source code
java/j2ee source code  java/j2ee source code for online food purchasing service with my sql database

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.