java简单的接口程序

import java.util.Arrays;

public class Grapeh {
	public static void main(String[] args) {
     	Employee[] staff=new Employee[3];
     	staff[0]=new Employee("heln",5003);
     	staff[1]=new Employee("mell",1000);
     	staff[2]=new Employee("kell",500);
     	Arrays.sort(staff);
     	for(Employee e:staff)
     		System.out.println("name="+e.getName()+",salary="+e.getSalary());
	}
}

public class Employee implements Comparable<Employee>{
	private String name;
	private double salary;
	public Employee(String n ,double s){
		name=n;
		salary=s;
	}
	public String getName(){
		return name;
	}
	public double getSalary(){
		return salary;
	}
	public void raiseSalary(double byPercent){
		double raise=salary*byPercent/100;
		salary+=raise;
	}
	public int compareTo(Employee other){
		return Double.compare(salary, other.salary);
	}
	
}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。