dec201612
class Employee
{
private String name;
private double salary;
public Employee(String name,double salary){
this.name=name;
this.salary=salary;
}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public double getSalary(){
return salary;
}
public void setSalary(double salary){
this.salary=salary;
}
public static void main(String [] args){
Employee[] Employees=new Employee[5];
Employees[0]=new Employee("zhang",1200);
Employees[1]=new Employee("wang",1300);
Employees[2]=new Employee("li",1400);
Employees[3]=new Employee("zhou",1500);
Employees[4]=new Employee("zhao",1600);
new Test(){
public void search(String name,Employee[] arr){
int num=0;
for(Employee em:arr){
if (name.equals(em.getName())){
System.out.println(em.toString());
return;
}
else
{
num++;
}
}
if(num>0){
System.out.println("没有这个人名");
}
}
}.search("zhang",Employees);
Test t=(String name,Employee[] arr)->{
int num=0;
for(Employee em:arr){
if (name.equals(em.getName())){
System.out.println(em.toString());
return;
}
else
{
num++;
}
}
if(num>0){
System.out.println("没有这个人名");
}
};
t.search("li",Employees);
}
public String toString(){
return "姓名:"+this.getName()+"\n"+"salary:"+this.getSalary();
}
}
interface Test{
void search(String name,Employee[] arr);
}
out: