1700466843
1700466844
private int num=0;
1700466845
1700466846
//项目费用
1700466847
1700466848
private int cost=0;
1700466849
1700466850
//定义一个构造函数,把所有老板需要看到的信息存储起来
1700466851
1700466852
public Project(String name,int num,int cost){
1700466853
1700466854
//赋值到类的成员变量中
1700466855
1700466856
this.name=name;
1700466857
1700466858
this.num=num;
1700466859
1700466860
this.cost=cost;
1700466861
1700466862
}
1700466863
1700466864
//得到项目的信息
1700466865
1700466866
public String getProjectInfo(){
1700466867
1700466868
String info=””;
1700466869
1700466870
//获得项目的名称
1700466871
1700466872
info=info+“项目名称是:”+this.name;
1700466873
1700466874
//获得项目人数
1700466875
1700466876
info=info+”\t项目人数:”+this.num;
1700466877
1700466878
//项目费用
1700466879
1700466880
info=info+”\t项目费用:”+this.cost;
1700466881
1700466882
return info;
1700466883
1700466884
}
1700466885
1700466886
}
1700466887
1700466888
实现类也是极度简单,通过构造函数把要显示的数据传递过来,然后放到getProjectInfo中显示,这太容易了!然后我们老大要看看结果了,如代码清单20-3所示。
1700466889
1700466890
代码清单20-3 老大看报表的场景
1700466891
1700466892
public class Boss{
[
上一页 ]
[ :1.700466843e+09 ]
[
下一页 ]