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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


chandru
Quries
1 Answer(s)      3 years and 8 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).


Advertisement
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 Tutorials/Questions & Answers:
sql quries
sql quries  i want basic sql quries please provide
Advertisements
uploading image in the form
they logged into the screen. Im using Orcale database(sql quries to check
CHECK WHICH NO IS GREATER IN 4 NO'S
chaudhary(+919261377137) if you want to ask any quries then contact me or email
 

 

 

DMCA.com