是运行出来了,请问还有哪里要改进的地方吗?

来源:2-8 编程练习

Roem

2020-02-11 13:38:50

public class Test {
    public static void main(String[] args) {
		System.out.print("父类信息测试:");
	    Work ow = new Work();
		ow.work();
		System.out.print("测试工作类信息测试:");
	    TestWork tw = new TestWork(10,5);
		tw.setName("测试工作");
		tw.work();
		System.out.print("研发工作类信息测试:");
    	DevelopmentWork dw = new DevelopmentWork(1000,10);
		dw.setName("研发工作");
		dw.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() {
System.out.println("开心工作");
return null;
    }
}
=====================
public class TestWork extends Work {
    //属性:编写的测试用例个数、发现的Bug数量
    private int testnum,bugnum;
public TestWork() {

}
    // 编写构造方法,并调用父类相关赋值方法,完成属性赋值
public TestWork(int testnum,int bugnum) {
this.setBugnum(bugnum);
this.setTestnum(testnum);
}
    // 公有的get***/set***方法完成属性封装
    public int getTestnum() {
return testnum;
}
public void setTestnum(int testnum) {
this.testnum = testnum;
}
public int getBugnum() {
return bugnum;
}
public void setBugnum(int bugnum) {
this.bugnum = bugnum;
}
// 重写运行方法,描述内容为:**的日报是:今天编写了**个测试用例,发现了**bug。其中**的数据由属性提供
    public String work() {
System.out.println(this.getName()+"的日报是:今天编写了"+this.testnum+"个测试用例,发现了"+this.bugnum+"个bug。");
return null ;
}
}
================================
public class DevelopmentWork extends Work {
    // 属性:有效编码行数、目前没有解决的Bug个数
private int codeline,probug;
public DevelopmentWork() {

}
//编写构造方法,并调用父类相关赋值方法,完成属性赋值
public DevelopmentWork(int codeline,int probug) {
this.setCodeline(codeline);
this.setProbug(probug);
}
    // 公有的get***/set***方法完成属性封装
public int getCodeline() {
return codeline;
}
public void setCodeline(int codeline) {
this.codeline = codeline;
}
public int getProbug() {
return probug;
}
public void setProbug(int probug) {
this.probug = probug;
}
// 重写运行方法,描述内容为:**的日报是:今天编写了**行代码,目前仍然有**个bug没有解决。其中**的数据由属性提供
public String work() {
        System.out.println(this.getName()+"的日报是:今天编写了"+this.getCodeline()+"行代码,目前仍然有"+this.getProbug()+"个bug没有解决。");
return null;
}
}


写回答

1回答

好帮手慕雪

2020-02-11

同学需要注意

http://img.mukewang.com/climg/5e425cad09ab47e603490130.jpg

根据单一职责,可知每个方法,不要牵扯太多,所以这里最好把“开心工作”返回,而调用者拿到数据后,是要显示还是保存,那是调用者的事情,不要把print写在work中,要在主方法中去输出 。如果解决了你的疑惑,请采纳,祝学习愉快~ 

0

0 学习 · 2907 问题

查看课程