// 我必须在这个问题中实现排队论。我必须生成一个随机值并将这些值存储在一个文件中。我正在尝试创建多个文件来存储不同范围的值。但我做不到。我只能创建第一个文件是 VariableInputRate.txt 而不是其他文件。我也需要帮助来创建其他文件。否则有什么方法可以组合这两个值并将其保存在一个文件中。谢谢
String path1 = "c://VariableInputRate(0-10).txt";
for(int i = 0 ; i < x/10 ; i ++ )
{
y= Math.random(); //call a random number generator
//to generate a random number between 0 and 1
if(y <= in_rate1 /(in_rate1 + out_rate))
{
if(pkt_in_q < n)
pkt_in_q ++;
else
pkt_dropped ++;
}
else
{
if(pkt_in_q > 0)
pkt_in_q --;
}
File file = new File(path1);
try {
file.createNewFile();
}
catch (IOException e){
e.printStackTrace();
}
try {
FileWriter fw = new FileWriter(file, true);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("For Event " + (i+1) +" we get: ");
//bw.newLine();
bw.write("No. of packets in the queue = " + pkt_in_q +" and no. of packets dropped = "+ pkt_dropped);
bw.newLine();
bw.flush();
bw.close();
fw.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
System.out.println("Please take at output 1.");
String path2 = "c://VariableInputRate(10-70).txt"; //Depends on which disk you are using, e.g. C,D,E,F disk
for( int i=j/10 ; i < k/70 ; i ++ )
{
y= Math.random(); //call a random number generator
//to generate a random number between 0 and 1
if(y <= in_rate2 /(in_rate2 + out_rate))
{
if(pkt_in_q < n)
pkt_in_q ++;
else
pkt_dropped ++;
}
else
{
if(pkt_in_q > 0)
pkt_in_q --;
}
File file = new File(path2);
try {
file.createNewFile();
}
catch (IOException e){
e.printStackTrace();
}
try {
FileWriter fw2 = new FileWriter(file, true);
BufferedWriter bw2 = new BufferedWriter(fw2);
bw2.write("For Event " + (i+1) +" we get: ");
//bw.newLine();
bw2.write("No. of packets in the queue = " + pkt_in_q +" and no. of packets dropped = "+ pkt_dropped);
bw2.newLine();
bw2.flush();
bw2.close();
fw2.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
System.out.println("Please take at output 2.");