chandru
Quries
1 Answer(s)      a year and 9 months ago
Posted in : Java Beginners

Write a program to accept an array list of employee objects and search for a particular Employee based on id number (like id, name & address).

View Answers

August 4, 2011 at 10:45 AM


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

class  Employee{
    int no;
    String name;
    String address;

    Employee(int no,String name,String address){
        this.no=no;
        this.name=name;
        this.address=address;

    }
    public int getNo(){
        return no;
    }
    public String getName(){
        return name;
    }
    public String getAddress(){
        return address;
    }

    public static void main(String[] args){
        ArrayList<Employee> list=new ArrayList<Employee>();
        Scanner input=new Scanner(System.in);
        for(int i=0;i<4;i++){
            System.out.println();
            System.out.println("-----Employee "+(i+1)+"-----");
            System.out.println("Enter id: ");
            int no=input.nextInt();
            System.out.println("Enter name: ");
            String name=input.next();
            System.out.println("Enter address: ");
            String address=input.next();
            list.add(new Employee(no,name,address));
        }
System.out.println(" ");
System.out.print("Enter Employee Id to search: ");
int id = input.nextInt();
for(Employee s : list){
if(id == s.getNo())
{
System.out.print(s.getNo()+" "+s.getName()+" " +s.getAddress());
}
}
}
}









Related Pages:
sql quries
sql quries  i want basic sql quries please provide
CHECK WHICH NO IS GREATER IN 4 NO'S
chaudhary(+919261377137) if you want to ask any quries then contact me or email

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.