Monday, January 20, 2014

Java Program to illustrate Package

with 0 Comment
package employee1;
public class empsearch1
{
public static int count=0;
public String emp_name;
public int emp_no,salary;
public empsearch1(String name,int no,int sal)
{
emp_name=name;
emp_no=no;
salary=sal;
}
public void perdis()
{
System.out.println("\t"+emp_name+"\t"+emp_no+"\t"+salary);
}
public int search1(int n,int n1)
{
if(emp_no!=n)
{
++count;
}
else
{
System.out.println("Employee Number:"+emp_no);
System.out.println("Employee Name:"+emp_name);
System.out.println("Employee Salary:"+salary);
}
return count;
}
}


Main Program:
*********
import employee1.*;
import java.io.*;
class employeedel1
{
public static void main(String args[])throws IOException
{
DataInputStream s=new DataInputStream(System.in);
String name;
int emp_no,sal,num,i,n,ch,co=0,emp=0;
System.out.println("Employee Details");
System.out.println("---------------");
System.out.print("Enter the number of employees:");
num=Integer.parseInt(s.readLine());
empsearch1 r[]=new empsearch1[100];
for(i=1;i<=num;i++)
{
System.out.println("\n\n Enter Employee "+i+" detail");
System.out.print("Enter the employee name:");
name=s.readLine();
System.out.print("Enter the employee number:");
emp_no=Integer.parseInt(s.readLine());
System.out.println("Enter the employee salary:");
sal=Integer.parseInt(s.readLine());
r[i]=new empsearch1(name,emp_no,sal);
}
System.out.println("\n\t*************");
System.out.println("\tName\tNumber\tSalary");
System.out.println("\t**************");
for(i=1;i<=num;i++)
{
r[i].perdis();
}
System.out.println("\t**********************");
System.out.print("Enter the Empoyee Number to be Searched:"):
n=Integer.parseInt(s.readLine());
for(i=1;i<=num;i++)
{
co=r[i].search1(n,num);
}
if(co==num)
{
System.out.println("No Data Found");
}
else
{
System.out.println();
}
}
}


-------------
OUTPUT:
------------
D:\IIMCA\11MCA13>javac employee1\empsearch1.java
D:\IIMCA\11MCA13>java employeedel1

Employee Details
---------------------
Enter the number of employees:3

Enter employee 1 Detail
Enter the employee name:Ashok
Enter the employee number:102
Enter the employee salary:12000

Enter employee 2 Detail
Enter the employee name:Arun
Enter the employee number:103
Enter the employee salary:10000

Enter employee 3 Detail
Enter the employee name:Raji
Enter the employee number:104
Enter the employee salary:15000

**********************************************
Name                      Number                Salary
**********************************************
Ashok                        102                  12000
Arun                          103                  10000
Raji                           104                   15000
**********************************************

Enter the Employee Number to be Searched: 102

Enter the employee number:102
Enter the employee name:Ashok
Enter the employee salary:12000

Enter the Employee Number to be Searched:105

No Data Found

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive