麻烦老师看看代码有哪里可以优化吗
来源:2-8 编程练习
小老哥丶
2019-09-24 17:29:27
public class Test {
public static void main(String[] args) {
System.out.print("父类信息测试:");
Work work=new Work("开心工作");
System.out.println(work.work());
System.out.print("测试工作类信息测试:");
TestWork testWork=new TestWork(10,5,"测试工作");
System.out.println(testWork.work());
System.out.print("研发工作类信息测试:");
DevelopmentWork devWork=new DevelopmentWork(1000,10,"研发工作");
System.out.println(devWork.work());
}
}public class Work {
// 属性:工作ming
private String name ;
// 无参构造方法
public Work(){}
// 带参构造方法,完成工作类型的赋值
public Work(String name)
{
this.setName(name);
}
// 公有的get***/set***方法完成属性封装
public String getName(){
return this.name;
}
public void setName(String name){
this.name=name;
}
// 方法:工作描述,描述内容为:开心工作
public String work() {
String str=this.name;
return str;
}
}public class TestWork extends Work {
//属性:编写的测试用例个数、发现的Bug数量
private int yl;
private int bug;
// 编写构造方法,并调用父类相关赋值方法,完成属性赋值
public TestWork(int yl,int bug,String name)
{
this.setYl(yl);
this.setBug(bug);
this.setName(name);
}
// 公有的get***/set***方法完成属性封装
public int getYl(){
return this.yl;
}
public void setYl(int yl)
{
this.yl=yl;
}
public int getBug(){
return this.bug;
}
public void setBug(int bug)
{
this.bug=bug;
}
// 重写运行方法,描述内容为:**的日报是:今天编写了**个测试用例,发现了**bug。其中**的数据由属性提供
public String work() {
String str=this.getName()+"的日报是:今天编写了"+this.getYl()+"个测试用例,发现了"+this.getBug()+"个bug。";
return str;
}
}public class DevelopmentWork extends Work {
// 属性:有效编码行数、目前没有解决的Bug个数
private int hs;
private int bug;
//编写构造方法,并调用父类相关赋值方法,完成属性赋值
public DevelopmentWork(int hs,int bug,String name)
{
this.setHs(hs);
this.setBug(bug);
this.setName(name);
}
// 公有的get***/set***方法完成属性封装
public int getHs(){
return this.hs;
}
public void setHs(int hs)
{
this.hs=hs;
}
public int getBug()
{
return this.bug;
}
public void setBug(int bug)
{
this.bug=bug;
}
// 重写运行方法,描述内容为:**的日报是:今天编写了**行代码,目前仍然有**个bug没有解决。其中**的数据由属性提供
public String work(){
String str=this.getName()+"的日报是:今天编写了"+this.getHs()+"行代码,目前仍然有"+this.getBug()+"个bug没有解决。";
return str;
}
}1回答
同学你好,代码完成不错,不需要在优化啦~
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
相似问题