题目:请设计一个具备比较功能的类(例如 员工类, 需要有姓名, 年龄, 薪水三个成员属性需要私有并提供get, set方法, 可以通过构造函数进行初始化,并且按照薪水进行排序)。
我不知道我写代码符合题目不?请各位同学研究下!- public class Demo {
- public static void main(String[] args) {
- yuangong zhangs = new yuangong("zhangs",25,5000.00);
- yuangong lisiss = new yuangong("lisiss",67,1520.51);
- yuangong wangwu = new yuangong("wangwu",18,7841.00);
- yuangong shouli = new yuangong("shouli",45,7852.41);
- yuangong sdfefe = new yuangong("sdfefe",28,5842.55);
- yuangong sdfeAe = new yuangong("sdfeAe",22,3889.00);
- Object[] OBJ=new Object[]{zhangs,lisiss,wangwu,shouli,sdfefe,sdfeAe};
- zhangs.ReorderGzPrint(OBJ);}}
- class yuangong{
- private String name;
- private int age;
- private double gongzi;
- yuangong(String name){this.name=name;}
- yuangong(int age){this.age=age;}
- yuangong(double gongzi){this.gongzi =gongzi;}
- yuangong(String name,int age,double gongzi){
- this.name=name;this.age=age;this.gongzi=gongzi;}
- void Name_Get(){System.out.println(name);}
- void Age_Get(){System.out.println(age);}
- void Gongzi_get(){System.out.println(gongzi);}
- void QuanBu_get(){System.out.println(name+"\t"+age+"\t"+gongzi);}
- void ReorderGzPrint(Object[]aa){
- Object[] Obj=new Object[1];
- for(int a=0;a<=aa.length-1;a++){
- for(int b=0;b<=a;b++){
- if(a!=b)
- if(((yuangong)aa[a]).gongzi>((yuangong)aa[b]).gongzi)
- {Obj[0]=aa[a];aa[a]=aa[b];aa[b]=Obj[0];}}}
- for(int a=0;a<=aa.length-1;a++){((yuangong)aa[a]).QuanBu_get();}}}
复制代码 |
|