昨晚,通过朋友的帮助,现在程序还有一点错误,急盼回答!(在线等待)

yuanqingfei 2002-05-23 09:32:25
//:Csc.java
//computing the sedimenting tank;
import java.io.*;
import Geshan.*;

interface Index1{
double velocity=0.2;//设计流量时的水平流速,米/秒
double time=50;//最大设计流量时,污水在池内的停留时间,秒
double maxQ=Index.kTotal*20000.0/86400;//最大流量
double h2=1;//设计有效水深,米
double day=2;//计算沉砂斗体积时,按2天的沉砂量计,天
double x1=3;//城市污水沉沙量,立方米/十万立方米
double a1=0.5;//沉砂斗下底宽,米
double alpha=55;//沉砂斗壁与水平面的倾角,度
double n=4;//沉砂斗的个数
double minQ=20000.0/86400/3;
double po=0.06;//沉砂斗外侧的坡度
// double h3=0.7;沉砂斗的高度,米

}



public class Csc {
double L1=Index1.velocity*Index1.time;//水流部分长度,米
double A=Index1.maxQ/Index1.velocity;//水流断面积,平方米
double B=A/Index1.h2;//池总宽度,米
double V=86400*Index1.maxQ*Index1.day*Index1.x1/(100000*Index.kTotal);
//沉砂斗容积,立方米
double v=V/Index1.n;//每个沉砂斗的容积,立方米
double h3pie=0.0;
double rr=root(0.0,10.0,0.001,h3pie);

double a=2*h3pie/Math.tan(Index1.alpha*Math.PI/180)+Index1.a1;
//沉砂斗上口宽,米
double h3=h3pie+Index1.po*(L1-Index1.n/2*a)/2;//沉砂室总高,米
double H=Index1.h2+Index1.h2+h3;//沉砂池总高,米
double minV=Index1.minQ/(B/2*Index1.h2);



double f(double x,double x1,double x2){
return x1-(x2-x)*Math.tan(55*Math.PI/180)/12*(2*Math.pow(x2,2)+
2*x2*x+2*Math.pow(x,2));
}
double root(double y1,double y2,double y3,double y4){
double s1=f(y1,v,Index1.a1);
y4=(y1+y2)/2;
while (Math.abs(y2-y1)>y3){
double y5=0;
double y6=0;
double s2=f(y4,v,Index1.a1);
if(s2+1.0==1.0){
return y4;
}
if (s1*s2>0){
y5=y4;
}
else{
y6=y4;
}
y4=(y5+y6)/2;
}

}

public static void main(String[] args){
Csc csc=new Csc();

try {
DataOutputStream out2 =
new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream("Data.txt")));
out2.writeDouble(csc.L1);
out2.writeDouble(csc.A);
out2.writeDouble(csc.B);
out2.writeDouble(csc.V);
out2.writeDouble(csc.h3pie);
out2.writeDouble(csc.a);
out2.writeDouble(csc.h3);
out2.writeDouble(csc.H);
out2.writeDouble(csc.minV);
out2.writeDouble(Index.kTotal);
out2.close();
DataInputStream in5 =
new DataInputStream(
new BufferedInputStream(
new FileInputStream("Data.txt")));

// Must use DataInputStream for data:
System.out.println("L="+in5.readDouble());
System.out.println("A="+in5.readDouble());
System.out.println("B="+in5.readDouble());
System.out.println("V="+in5.readDouble());
System.out.println("h3pie="+in5.readDouble());
System.out.println("a="+in5.readDouble());
System.out.println("h3="+in5.readDouble());
System.out.println("H="+in5.readDouble());
System.out.println("minV"+in5.readDouble());
System.out.println("kTotal="+in5.readDouble());
} catch(EOFException e) {
System.out.println("End of stream");
}
}
}///:~
...全文
146 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuanqingfei 2002-05-23
  • 打赏
  • 举报
回复
你说的很对,
我这就改!
杨嚣 2002-05-23
  • 打赏
  • 举报
回复
如果 if(s2+1.0==1.0){
return y4;}
为假,最后一步y4=(y5+y6)/2;再第一次执行时y4就是0,是这样吧
yuanqingfei 2002-05-23
  • 打赏
  • 举报
回复
我们在另一个窗口重新谈
我将重贴一次修改后的程序
以及出现的错误!
yuanqingfei 2002-05-23
  • 打赏
  • 举报
回复
to smallnest:
你说的到了关键
其实我实际输入了数据,我通过了调用
double rr=root(0.0,10.0,0.001,h3pie);
就可以了
to zxy355:
其实Geshan是一个包,但没有别的意思,知识调用里面的数据
你可以用一个常数来代替。。
。。
杨嚣 2002-05-23
  • 打赏
  • 举报
回复
Geshan是你自定义的吗,还有Index1里的成员和方法是什么,我刚才在j++里编译了一下,没有Geshan这个包
colobu 2002-05-23
  • 打赏
  • 举报
回复
即使你能保证你输入的数据肯定会出现s2+1.0==1.0的情况
但java不知道啊,因为你还没实际输入数据,
所以java会认为 有!(s2+1.0==1.0))且退出while的情况

在这种情况下你必须有个返回值
colobu 2002-05-23
  • 打赏
  • 举报
回复
在循环中
即使不会出现
yuanqingfei 2002-05-23
  • 打赏
  • 举报
回复
double root(double y1,double y2,double y3,double y4){
double s1=f(y1,v,Index1.a1);
y4=(y1+y2)/2;
while (Math.abs(y2-y1)>y3){
double y5=0;
double y6=0;
double s2=f(y4,v,Index1.a1);
if(s2+1.0==1.0){
return y4;/*请smallnest 注意,在这里。if(!(s2+1.0==1.0))那么继续循环,直到这儿再返回!*/
}
if (s1*s2>0){
y5=y4;
}
else{
y6=y4;
}
y4=(y5+y6)/2;
}

}
colobu 2002-05-23
  • 打赏
  • 举报
回复
root总要有个返回值,

if (!(s2+1.0==1.0))

请问你的return在哪里
yuanqingfei 2002-05-23
  • 打赏
  • 举报
回复
加上static 也不行
请大家再仔细看一下
问题的症结!
yuanqingfei 2002-05-23
  • 打赏
  • 举报
回复
to smallnest:
Index只是用来提供static final 的数据
root()方法里用的是二分法
是迭代
其中有return y4;
对于异常的建议,我接受!
colobu 2002-05-23
  • 打赏
  • 举报
回复
你在声明的前面加上static不就行了
yuanqingfei 2002-05-23
  • 打赏
  • 举报
回复
是这样的,如果把interface 改为final class
就会出现这样的错误:
Csc.java:25:non-static variable velocity cannot be referenced
from a static context
还有
如果把out2.writeDouble(csc.L1);
out2.writeDouble(csc.A);
out2.writeDouble(csc.B);
out2.writeDouble(csc.V);
out2.writeDouble(csc.h3pie);
out2.writeDouble(csc.a);
out2.writeDouble(csc.h3);
out2.writeDouble(csc.H);
out2.writeDouble(csc.minV);
中的csc.都去掉
就会出现同样的错误
但有,
回出现更多的错误。。。
colobu 2002-05-23
  • 打赏
  • 举报
回复
1.Index接口呢?

2.root函数的最后一行加上return y4;

3.程序的最后在
catch(EOFException e) {
System.out.println("End of stream");
}
的后面加上
catch(FileNotFoundException e) {
System.out.println("File Not Found");
}
catch(IOException e) {
System.out.println("IO Error");
}
gangyi 2002-05-23
  • 打赏
  • 举报
回复
interface不应该用来放static field。虽然语法上没问题,但是Java编程规范反对这样做。你可以用final class。
flylijian 2002-05-23
  • 打赏
  • 举报
回复
错误提示呢?

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧