package shiyan4_1; public class StreamLine { private DoThing one,two,three; StreamLine(){ one=new DoInput(); two=new DelMaxAndMin(); [代码5] one.setNext(two); [代码6] } public void giveResult(double a[]){ one.doThing(a); } }
时间: 2023-07-16 11:16:07 浏览: 105
这段代码中缺少一行代码,需要在构造函数中创建一个新的 DoOutput 对象,并将其设置为链的最后一个节点。代码5和6分别是创建 DoInput 对象和将其设置为链的第一个节点。
正确的代码应该是这样的:
```
package shiyan4_1;
public class StreamLine {
private DoThing one, two, three;
StreamLine() {
one = new DoInput();
two = new DelMaxAndMin();
three = new DoOutput(); // 新增代码
one.setNext(two);
two.setNext(three); // 修改代码
}
public void giveResult(double a[]) {
one.doThing(a);
}
}
```
这样就可以在链的最后一个节点进行输出操作了。
相关问题
package shiyan4_1; public class ComputerAver extends DoThing { DoThing nextDoThing ; public void setNext(DoThing next) { ____[代码4]_____ } public void doThing(double [] a) { double sum = 0; for(int i=0;i<a.length;i++) sum = sum+a[i]; double aver = sum/a.length; System.out.print("选手最后得分"+aver); } }
在代码4处,应该写上:
```
nextDoThing = next;
```
这个方法是用来设置链中的下一个处理对象。
package shiyan4_1; import java.util.*; public class DoInput extends DoThing { DoThing nextDoThing ; public void setNext(DoThing next) { _____[代码1]_____ } public void doThing(double [] a) { System.out.println("请输入裁判数"); Scanner read=new Scanner(System.in); int count = read.nextInt(); System.out.println("请输入各个裁判的分数"); a = new double[count]; for(int i=0;i<count;i++) { a[i]=read.nextDouble(); } nextDoThing.doThing(a); } }
在代码1处应该填写:
```
nextDoThing = next;
```
这行代码的作用是将当前对象的下一个处理者设置为传入的参数对象。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)