想知道我这些代码错在什么地方,还想老师给讲讲为甚set方法不好使了
来源:2-8 编程练习
qq_不会取名_0
2019-04-10 14:58:43
Test.Java
public class Test {
public static void main(String[] args) {
System.out.print("父类信息测试:");
Work one=new Work();
one.work();
System.out.println("\n");
System.out.print("测试工作类信息测试:");
TestWork two=new TestWork();
two.setTn(10);
two.setBn(5);
two.work();
System.out.println("\n");
System.out.print("研发工作类信息测试:");
DevelopmentWork three= new DevelopmentWork();
three.work();
}
}
Work.java
public class Test {
public static void main(String[] args) {
System.out.print("父类信息测试:");
Work one=new Work();
one.work();
System.out.println("\n");
System.out.print("测试工作类信息测试:");
TestWork two=new TestWork();
two.setTn(10);
two.setBn(5);
two.work();
System.out.println("\n");
System.out.print("研发工作类信息测试:");
DevelopmentWork three= new DevelopmentWork();
three.work();
}
}
Testwork.java
public class TestWork extends Work {
//属性:编写的测试用例个数、发现的Bug数量
private int tn,bn;
// 编写构造方法,并调用父类相关赋值方法,完成属性赋值
public TestWork(){
this.setName("测试类工作");
}
// 公有的get***/set***方法完成属性封装
public void setTn(){
this.tn=tn;
}
public int getTn(){
return this.tn;
}
public void setBn(){
this.bn=bn;
}
public int getBn(){
return this.bn;
}
// 重写运行方法,描述内容为:**的日报是:今天编写了**个测试用例,发现了**bug。其中**的数据由属性提供
public void work() {
System.out.println(this.getName()+"的日报是:"+"今天编写了"+this.getTn()+"个测试用例,"+"发现了"+this.getBn()+"个bug");
}
}
DevelopmentWork.java
public class DevelopmentWork extends Work {
// 属性:有效编码行数、目前没有解决的Bug个数
private int yb,nb;
//编写构造方法,并调用父类相关赋值方法,完成属性赋值
public DevelopmentWork(){
super.name;
name="研发工作"
}
// 公有的get***/set***方法完成属性封装
public void setYb(){
this.yb=yb;
}
public int getYb(){
return this.yb;
}
public void setNb(){
this.nb=nb;
}
public int getNb(){
return this.nb;
}
// 重写运行方法,描述内容为:**的日报是:今天编写了**行代码,目前仍然有**个bug没有解决。其中**的数据由属性提供
public void work() {
System.out.println(this.getName()+"的日报是:"+"今天编写了"+this.getYb()+
"代码,"+"目前任然有"+this.getNb()+"个bug没有解决");
}
}
2回答
吃吃吃鱼的猫
2019-04-12
同学你好,set方法需要参数为成员变量赋值。修改代码如下图所示:

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~
吃吃吃鱼的猫
2019-04-10
同学你好,请贴出复制后的完整代码。方便老师更快更好的解决同学的问题。如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~
相似问题