我是编码中的一个完整的菜鸟,我想知道我是否能得到一些帮助
我有这个项目,基本上我需要做的是:
创建2个可执行程序。翻译计划和字典计划。这些程序可以用任何语言编写。
翻译程序会将字典程序传递给英语单词。 Dictionary程序将翻译并返回一个外来单词。翻译程序将打印出英文单词并将其翻译成文件。
字典程序将查找英文单词并以外语返回其翻译。词典程序将能够将选定数量的英语单词翻译成另一种语言。词典程序将英语单词翻译成语言将由学生决定。词典程序将能够将至少15个英语单词翻译成外语。 “
现在我无法让Dictionary程序调用Translate程序。 我的导师告诉我们使用声明
Process proc = Runtime.getRuntime().exec("java -jar Translate.jar");
InputStream in = proc.getInputStream();
InputStream err= proc.getErrorStream();
目前问题是我的程序似乎无法访问jar文件。 我正在使用Eclipse和Windows 7 我创建Translate jar文件的步骤是
现在我只有两个程序的伪代码,但我专注于搞清楚如何调用翻译程序。
public class Dictionary {
public static void main(String [] args){
/******************
* Dictionary Program
* Will translate and return a foreign word back
* to the Translate program that this Program is calling.
* It will look up the English word. The Dictionary will use
* Elvish as the foreign language that is being translated.
* Should be able to translate 15 english words.
*/
/**********************************************************
/* External Module code calls Translate and gets output
*from module
/*********************************************************/
/* try
{
// Run a java app in a separate system process
Process proc = Runtime.getRuntime().exec("java -jar Translate.jar");
// Then retreive the process output
InputStream in = proc.getInputStream();
InputStream err= proc.getErrorStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String EngWord = reader.readLine(); //EngWord is the variable sent from the Translate program
while ( (EngWord = reader.readLine()) != null)
do //Pseudo-code of (If, Else Statements provided below)
/**********************************************************************
* Pseudo-code
**********************************************************************/
String EngWord = "Should be a variable that the Translate Program is passing that is the english word";
String foreignWord = "A variable created by this Diction program that will be sent back to the Translate program";
if (EngWord == "dog") {
foreignWord = "elvish equivalent";
} else if (EngWord == "cat") {
foreignWord = "cat in elvish";
} else if (EngWord == "tree"){
foreignWord = "tree in elven";
} else {
EngWord = "nothing? something that can end the loop well";
// I guess this is where the loop must terminate
}
//Must find a way to return the foreignWord back to Translate
/*
} catch (Throwable e){
e.printStackTrace();
}
*/
}
}
public class Translate {
/**************************
* Translate program will pass the Dictionary program
* an English word. When the Dictionary program translate and returns an Elvish word
* This program will print out the English word and its translation into a file
*
*/
public static void main(String [] args) {
//Must find a way to pass the english word to Dictionary
String EngWord = "This is the variable being sent to the Dictionary program...use as parameter?";
//Must use some type of Writer class in order to write the output of both the EngWord and foreignWord
//into an Output file
String foreignWord = "THis is the variable being sent back from the Dictionary program";
//perhaps use runtime before this so Translate can retreive foreignWord from Dictionary?
//Some type of algorithm that will write both the foreignWord and Engword onto an output file.
//Prints (Writes) out to "output.txt"
}
}
如果我不被允许接受这么多的帮助,有人可能会告诉我其他网站可能会被允许发布此请求吗?