主题:请高手来帮忙改一下程序中的错误
import java.io.*;
import java.math.*;
import java.util.*;
import java.math.*;
import java.lang.*;
public class DHT
{
class node1//定义三个节点
{
int node1_id=1;
}
class node2
{
int node2_id=2;
}
class node3
{
int node3_id=3;
}
class node_require_table_node1//请求交易节点1的数据结构表
{
int S1s2=10,S1s3=10,F1s2=10,F1s3=10,I1s2=10,I1s3=10;
double Cr12=0.5,Cr13=0.5;
int K12=10,K13=10;
}
class node_require_table_node2//请求交易节点2的数据结构表
{
int S2s1=10,S2s3=10,F2s1=10,F2s3=10,I2s1=10,I2s3=10;
double Cr21=0.5,Cr23=0.5;
int K21=10,K23=10;
}
class node_require_table_node3//请求交易节点3的数据结构表
{
int S3s1=10,S3s2=10,F3s1=10,F3s2=10,I3s1=10,I3s2=10;
double Cr31=0.5,Cr32=0.5;
int K31=10,K32=10;
}
class BinarySearch//在本地数据表中查找Cr
{
double[] Cr={0.5,0.5,0.5,0.5,0.5,0.5};
int first=0;
int last=Cr.length-1;
int mid;
int binarySearch(double [] Cr,int key)
{
while(first<=last)
{
mid=(first+last)/2;
if(Cr[mid]==key)
return mid;
if(Cr[mid]>key)
last=mid-1;
if(Cr[mid]<key)
first=mid+1;
}
return 0;
}
}
class EvalTrans
{
void EvalTrans() ///随机生成一个0,1值,0代表交易失败,1代表交易成功
{
String randStr = "01";
int intRd = 0; //存放随机数
int countS = 0; //记录生成的随机数个数
int countF = 0; //记录生成的随机数个数
StringBuffer EvalTrans=new StringBuffer();
Random rand = new Random();
int randStrLength = 1;
for (int i = 0; i < randStrLength; i++)
{
int randNum = rand.nextInt(2);
EvalTrans.append(randStr.substring(randNum,randNum+1));
if(randNum==0)
countS++;
else
countF++;
}
}
}
class Update1 //更新结点1的本地数据表
{
L12,L13,R12,R13,D12,D13,C12,C13,W12,W13,G12,G13
}
class Update2 //更新结点2的本地数据表
{
I21,L23,R21,R23,D21,D23,C21,C23,W21,W23,G21,G23
}
class Update3 //更新结点3的本地数据表
{
I31,L32,R31,R32,D31,D32,C31,C32,W31,W32,G31,G32
}
class compute1
{
void compute1()
{
int S12=10,S13=10,F12=10,F13=10,I12=20,I13=20;
double C12,C13,L12,L13,D12,D13,W12,W13,G12,G13,R12,R13,T1;
int K12=10,K13=10;
double alpha=0.8;
int beta=2;
I12=S12+F12;
L12=S12/I12;
L13=S13+F13;
I13=S13/I13;
R12=(S12-F12)/I12;
R13=(S13-F13)/I13;
D12=(L12-L13)/2;
D12=1-Math.sqrt(D12);
D13=(L12-L13)/2;
D13=1-Math.sqrt(D13);
C12=1-D12;
C13=1-D13;
T1=(R12+R13)*(C12+C13);
W12=1-Math.sqrt(Math.pow(0.8,K12));
W13=1-Math.sqrt(Math.pow(0.8,K13));
G12=W12*L12+(1-W12)*T1;
G13=W13*L13+(1-W13)*T1;
}
}
class compute2
{
void compute2()
{
int S21=10,S23=10,F21=10,F23=10,I21=20,I23=20;
double C21,C23,L21,L23,D21,D23,W21,W23,G21,G23,R21,R23,T2;
int K21=10,K23=10;
double alpha=0.8;
int beta=2;
I21=S21+F21;
L21=S21/I21;
I23=S23-F23;
L23=(S23+F23)/I23;
R21=(S21-F21)/I21;
R23=(S23-F23)/I23;
D21=(L21-L23)/2;
D21=Math.sqrt(D21);
D23=(L21-L23)/2;
D23=Math.sqrt(D23);
C21=1-D21;
C23=1-D23;
T2=(R21+R23)*(C21+C23);
W21=1-Math.sqrt(Math.pow(0.8,K21));
W23=1-Math.sqrt(Math.pow(0.8,K23));
G21=W21*L21+(1-W21)*T2;
G23=W23*L23+(1-W23)*T2;
}
}
class compute3
{
void compute3()
{
int S31=10,S32=10,F31=10,F32=10,I31=20,I32=20;
double C31,C32,L31,L32,D32,D31,W31,W32,G31,G32,R31,R32,T3;
int K31=10,K32=10;
double alpha=0.8;
int beta=2;
I31=S31+F31;
L31=S31/I31;
R31=(S31-F31)/I31;
R32=(S32-F32)/I32;
I32=S32+F32;
L32=(S32-F32)/I32;
D31=(L31-L32)/2;
D31=1-Math.sqrt(D31);
D32=(L31-L32)/2;
D32=1-Math.sqrt(D32);
C31=1-D31;
C32=1-D32;
T3=(R31+R32)*(C31+C32);
W31=1-Math.sqrt(Math.pow(0.8,K31));
W32=1-Math.sqrt(Math.pow(0.8,K32));
G31=W31*L31+(1-W31)*T3;
G31=W31*L31+(1-W31)*T3;
}
}
public static void main(String args[]) throws IOException
{
int S12=10,S13=10,F12=10,F13=10,I12=10,I13=10;
int S21=10,S23=10,F21=10,F23=10,I21=20,I23=20;
int S31=10,S32=10,F31=10,F32=10,I31=20,I32=20;
int i,j,node_require,node_exchange;
String str1,str2,str3;
BufferedReader buf;
buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("结点1与结点2交易的成功次数为:"+S12);
System.out.println("结点1与结点2交易的失败次数为:"+F12);
System.out.println("结点1与结点3交易的成功次数为:"+S13);
System.out.println("结点1与结点3交易的失败次数为:"+F13);
System.out.println("结点2与结点1交易的成功次数为:"+S21);
System.out.println("结点2与结点1交易的失败次数为:"+S23);
System.out.println("结点3与结点1交易的成功次数为:"+S31);
System.out.println("结点3与结点1交易的失败次数为:"+F31);
System.out.println("结点3与结点2交易的成功次数为:"+S32);
System.out.println("结点3与结点2交易的失败次数为:"+F32);
System.out.print("请输入交易请求节点:");
str1=buf.readLine(); // 将输入的文字指定给字符串变量str1
node_require=Integer.parseInt(str1); // 将str1转成int类型后给node_require存放
System.out.print("请输入交易节点:");
str2=buf.readLine(); // 将输入的文字指定给字符串变量str1
node_exchange=Integer.parseInt(str2); // 将str1转成int类型后给node_exchange存放
System.out.print("请输入交易次数:");
str3=buf.readLine(); // 将输入的文字指定给字符串变量str1
i=Integer.parseInt(str3); // 将str1转成int类型后给i存放
switch(node_require='1')
{
case 1:
node_exchange='1';
System.out.println("不能与自身结点进行交易!");
break;
case 2:
node_exchange='2';
compute1 L12=new compute1();
if(L12>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else if
{
binarySearch c=new binarySearch();
if(0)
if(G12>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else
System.out.println("Exchange fail");
else
System.out.println("Exchange fail");
}
break;
case 3:
node_exchange='3';
if(L13>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else if
{
binarySearch c=new binarySearch();
if(0)
if(G13>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else
System.out.println("Exchange fail");
else
System.out.println("Exchange fail");
break;
}
switch(node_require='2')
{
case 1:
node_exchange='2';
System.out.println("不能与自身结点进行交易!");
break;
case 2:
node_exchange='1';
if(L21>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else if
{
binarySearch c=new binarySearch();
if(0)
if(G21>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else
System.out.println("Exchange fail");
else
System.out.println("Exchange fail");
break;
case 3:
node_exchange='3';
if(L32>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else if
{
binarySearch c=new binarySearch();
if(0)
if(G32>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else
System.out.println("Exchange fail");
else
System.out.println("Exchange fail");
break;
}
switch(node_require='3')
{
case 1:
node_exchange='3';
System.out.println("不能与自身结点进行交易");
break;
case 2:
node_exchange='1';
if(L31>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else if
{
binarySearch c=new binarySearch();
if(0)
if(G31>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else
System.out.println("Exchange fail");
else
System.out.println("Exchange fail");
break;
case 3:
node_exchange='2';
if(L32>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else if
{
binarySearch c=new binarySearch();
if(0)
if(G32>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else
System.out.println("Exchange fail");
else
System.out.println("Exchange fail");
break;
}
}
System.out.println("不能与自身结点进行交易!");
System.out.println("交易请求节点:"+node_require);
System.out.println("交易节点:"+node_exchange);
System.out.println("交易成功次数:"+S);
System.out.println("交易失败次数:"+F);
System.out.println("局部可信度:"+L);
System.out.println("推荐信任度:"+C);
System.out.println("全局信任度:"+G);
}
}
这是我写的一个关于信任计算的一个程序,本人初学JAVA,这个程序中有很多错误改不过来了,请高手帮忙改一下,万分感谢
import java.math.*;
import java.util.*;
import java.math.*;
import java.lang.*;
public class DHT
{
class node1//定义三个节点
{
int node1_id=1;
}
class node2
{
int node2_id=2;
}
class node3
{
int node3_id=3;
}
class node_require_table_node1//请求交易节点1的数据结构表
{
int S1s2=10,S1s3=10,F1s2=10,F1s3=10,I1s2=10,I1s3=10;
double Cr12=0.5,Cr13=0.5;
int K12=10,K13=10;
}
class node_require_table_node2//请求交易节点2的数据结构表
{
int S2s1=10,S2s3=10,F2s1=10,F2s3=10,I2s1=10,I2s3=10;
double Cr21=0.5,Cr23=0.5;
int K21=10,K23=10;
}
class node_require_table_node3//请求交易节点3的数据结构表
{
int S3s1=10,S3s2=10,F3s1=10,F3s2=10,I3s1=10,I3s2=10;
double Cr31=0.5,Cr32=0.5;
int K31=10,K32=10;
}
class BinarySearch//在本地数据表中查找Cr
{
double[] Cr={0.5,0.5,0.5,0.5,0.5,0.5};
int first=0;
int last=Cr.length-1;
int mid;
int binarySearch(double [] Cr,int key)
{
while(first<=last)
{
mid=(first+last)/2;
if(Cr[mid]==key)
return mid;
if(Cr[mid]>key)
last=mid-1;
if(Cr[mid]<key)
first=mid+1;
}
return 0;
}
}
class EvalTrans
{
void EvalTrans() ///随机生成一个0,1值,0代表交易失败,1代表交易成功
{
String randStr = "01";
int intRd = 0; //存放随机数
int countS = 0; //记录生成的随机数个数
int countF = 0; //记录生成的随机数个数
StringBuffer EvalTrans=new StringBuffer();
Random rand = new Random();
int randStrLength = 1;
for (int i = 0; i < randStrLength; i++)
{
int randNum = rand.nextInt(2);
EvalTrans.append(randStr.substring(randNum,randNum+1));
if(randNum==0)
countS++;
else
countF++;
}
}
}
class Update1 //更新结点1的本地数据表
{
L12,L13,R12,R13,D12,D13,C12,C13,W12,W13,G12,G13
}
class Update2 //更新结点2的本地数据表
{
I21,L23,R21,R23,D21,D23,C21,C23,W21,W23,G21,G23
}
class Update3 //更新结点3的本地数据表
{
I31,L32,R31,R32,D31,D32,C31,C32,W31,W32,G31,G32
}
class compute1
{
void compute1()
{
int S12=10,S13=10,F12=10,F13=10,I12=20,I13=20;
double C12,C13,L12,L13,D12,D13,W12,W13,G12,G13,R12,R13,T1;
int K12=10,K13=10;
double alpha=0.8;
int beta=2;
I12=S12+F12;
L12=S12/I12;
L13=S13+F13;
I13=S13/I13;
R12=(S12-F12)/I12;
R13=(S13-F13)/I13;
D12=(L12-L13)/2;
D12=1-Math.sqrt(D12);
D13=(L12-L13)/2;
D13=1-Math.sqrt(D13);
C12=1-D12;
C13=1-D13;
T1=(R12+R13)*(C12+C13);
W12=1-Math.sqrt(Math.pow(0.8,K12));
W13=1-Math.sqrt(Math.pow(0.8,K13));
G12=W12*L12+(1-W12)*T1;
G13=W13*L13+(1-W13)*T1;
}
}
class compute2
{
void compute2()
{
int S21=10,S23=10,F21=10,F23=10,I21=20,I23=20;
double C21,C23,L21,L23,D21,D23,W21,W23,G21,G23,R21,R23,T2;
int K21=10,K23=10;
double alpha=0.8;
int beta=2;
I21=S21+F21;
L21=S21/I21;
I23=S23-F23;
L23=(S23+F23)/I23;
R21=(S21-F21)/I21;
R23=(S23-F23)/I23;
D21=(L21-L23)/2;
D21=Math.sqrt(D21);
D23=(L21-L23)/2;
D23=Math.sqrt(D23);
C21=1-D21;
C23=1-D23;
T2=(R21+R23)*(C21+C23);
W21=1-Math.sqrt(Math.pow(0.8,K21));
W23=1-Math.sqrt(Math.pow(0.8,K23));
G21=W21*L21+(1-W21)*T2;
G23=W23*L23+(1-W23)*T2;
}
}
class compute3
{
void compute3()
{
int S31=10,S32=10,F31=10,F32=10,I31=20,I32=20;
double C31,C32,L31,L32,D32,D31,W31,W32,G31,G32,R31,R32,T3;
int K31=10,K32=10;
double alpha=0.8;
int beta=2;
I31=S31+F31;
L31=S31/I31;
R31=(S31-F31)/I31;
R32=(S32-F32)/I32;
I32=S32+F32;
L32=(S32-F32)/I32;
D31=(L31-L32)/2;
D31=1-Math.sqrt(D31);
D32=(L31-L32)/2;
D32=1-Math.sqrt(D32);
C31=1-D31;
C32=1-D32;
T3=(R31+R32)*(C31+C32);
W31=1-Math.sqrt(Math.pow(0.8,K31));
W32=1-Math.sqrt(Math.pow(0.8,K32));
G31=W31*L31+(1-W31)*T3;
G31=W31*L31+(1-W31)*T3;
}
}
public static void main(String args[]) throws IOException
{
int S12=10,S13=10,F12=10,F13=10,I12=10,I13=10;
int S21=10,S23=10,F21=10,F23=10,I21=20,I23=20;
int S31=10,S32=10,F31=10,F32=10,I31=20,I32=20;
int i,j,node_require,node_exchange;
String str1,str2,str3;
BufferedReader buf;
buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("结点1与结点2交易的成功次数为:"+S12);
System.out.println("结点1与结点2交易的失败次数为:"+F12);
System.out.println("结点1与结点3交易的成功次数为:"+S13);
System.out.println("结点1与结点3交易的失败次数为:"+F13);
System.out.println("结点2与结点1交易的成功次数为:"+S21);
System.out.println("结点2与结点1交易的失败次数为:"+S23);
System.out.println("结点3与结点1交易的成功次数为:"+S31);
System.out.println("结点3与结点1交易的失败次数为:"+F31);
System.out.println("结点3与结点2交易的成功次数为:"+S32);
System.out.println("结点3与结点2交易的失败次数为:"+F32);
System.out.print("请输入交易请求节点:");
str1=buf.readLine(); // 将输入的文字指定给字符串变量str1
node_require=Integer.parseInt(str1); // 将str1转成int类型后给node_require存放
System.out.print("请输入交易节点:");
str2=buf.readLine(); // 将输入的文字指定给字符串变量str1
node_exchange=Integer.parseInt(str2); // 将str1转成int类型后给node_exchange存放
System.out.print("请输入交易次数:");
str3=buf.readLine(); // 将输入的文字指定给字符串变量str1
i=Integer.parseInt(str3); // 将str1转成int类型后给i存放
switch(node_require='1')
{
case 1:
node_exchange='1';
System.out.println("不能与自身结点进行交易!");
break;
case 2:
node_exchange='2';
compute1 L12=new compute1();
if(L12>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else if
{
binarySearch c=new binarySearch();
if(0)
if(G12>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else
System.out.println("Exchange fail");
else
System.out.println("Exchange fail");
}
break;
case 3:
node_exchange='3';
if(L13>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else if
{
binarySearch c=new binarySearch();
if(0)
if(G13>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else
System.out.println("Exchange fail");
else
System.out.println("Exchange fail");
break;
}
switch(node_require='2')
{
case 1:
node_exchange='2';
System.out.println("不能与自身结点进行交易!");
break;
case 2:
node_exchange='1';
if(L21>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else if
{
binarySearch c=new binarySearch();
if(0)
if(G21>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else
System.out.println("Exchange fail");
else
System.out.println("Exchange fail");
break;
case 3:
node_exchange='3';
if(L32>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else if
{
binarySearch c=new binarySearch();
if(0)
if(G32>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else
System.out.println("Exchange fail");
else
System.out.println("Exchange fail");
break;
}
switch(node_require='3')
{
case 1:
node_exchange='3';
System.out.println("不能与自身结点进行交易");
break;
case 2:
node_exchange='1';
if(L31>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else if
{
binarySearch c=new binarySearch();
if(0)
if(G31>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else
System.out.println("Exchange fail");
else
System.out.println("Exchange fail");
break;
case 3:
node_exchange='2';
if(L32>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else if
{
binarySearch c=new binarySearch();
if(0)
if(G32>=0.4)
{
EvalTrans t=new EvalTrans();
Update u=new Update();
}
else
System.out.println("Exchange fail");
else
System.out.println("Exchange fail");
break;
}
}
System.out.println("不能与自身结点进行交易!");
System.out.println("交易请求节点:"+node_require);
System.out.println("交易节点:"+node_exchange);
System.out.println("交易成功次数:"+S);
System.out.println("交易失败次数:"+F);
System.out.println("局部可信度:"+L);
System.out.println("推荐信任度:"+C);
System.out.println("全局信任度:"+G);
}
}
这是我写的一个关于信任计算的一个程序,本人初学JAVA,这个程序中有很多错误改不过来了,请高手帮忙改一下,万分感谢