Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners java source code
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


deepanandakumar
java source code
2 Answer(s)      4 years and 5 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.

Advertisement
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 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
Advertisements
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
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  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
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 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, 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  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
Advertisements
 

 

 

DMCA.com