老师,这样写还有改进的空间吗?
来源:2-8 编程练习
小张一号
2020-02-17 11:40:45
public class Test { public static void main(String[] args) { System.out.print("父类信息测试:"); System.out.println(new Work()); System.out.print("测试工作类信息测试:"); System.out.println(new TestWork("测试工作", 5, 10)); System.out.print("研发工作类信息测试:"); System.out.println(new DevelopmentWork("研发工作", 1000, 10)); } }
public class Work { // 属性:工作ming private String name ; // 无参构造方法 Work() { } public String getName() { return this.name; } // 带参构造方法,完成工作类型的赋值 Work(String name) { this.name = name; } // 公有的get***/set***方法完成属性封装 // 方法:工作描述,描述内容为:开心工作 public String workDescript() { return "开心工作"; } public String toString() { return this.workDescript(); } }
public class TestWork extends Work { //属性:编写的测试用例个数、发现的Bug数量 private int bug_count; private int work_count; // 编写构造方法,并调用父类相关赋值方法,完成属性赋值 public TestWork(String name,int bug_count, int work_count) { super(name); this.bug_count = bug_count; this.work_count = work_count; } // 公有的get***/set***方法完成属性封装 // 重写运行方法,描述内容为:**的日报是:今天编写了**个测试用例,发现了**bug。其中**的数据由属性提供 public String workDescript() { return this.getName() + "的日报是:今天编写了" + this.work_count + "个测试用例, 发现了" + this.bug_count + "个bug"; } }
public class DevelopmentWork extends Work { // 属性:有效编码行数、目前没有解决的Bug个数 private int code_line; private int bug_count; //编写构造方法,并调用父类相关赋值方法,完成属性赋值 DevelopmentWork(String name,int code_line, int bug_count) { super(name); this.code_line = code_line; this.bug_count = bug_count; } // 公有的get***/set***方法完成属性封装 // 重写运行方法,描述内容为:**的日报是:今天编写了**行代码,目前仍然有**个bug没有解决。其中**的数据由属性提供 public String workDescript() { return this.getName() + "的日报是:今天编写了" + this.code_line + "行代码, 目前仍然有" + bug_count + "个bug没有解决"; } }
1回答
TestWork类中,最好为bug_count和t work_count;添加set,get方法,workDescript()
中调用对应的get方法。DevelopmentWork 类也是同理。如果解决了你的疑惑,请采纳,祝学习愉快~
相似问题