我是一个完全编码的菜鸟,我想知道是否可以得到一些帮助
我看到了这个项目,基本上我需要做的是:
创建 2 个可执行程序。一个翻译程序和一个字典程序。这些程序可以用任何语言编写。
Translate 程序将向 Dictionary 程序传递一个英文单词。Dictionary 程序将翻译并返回一个外来词。翻译程序将打印出英文单词并将其翻译成一个文件。
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 创建翻译 jar 文件的步骤是
- 右键单击翻译项目
 - 出口
 - 选定的可运行 Jar 文件
 - 选择字典 - 字典作为启动配置
 - 输入 Dictionary\Translate.jar 作为导出目的地
 - 单击完成,然后继续尝试使用 Process 运行时
 
现在我只有两个程序的伪代码,但我专注于弄清楚如何调用翻译程序。
字典.java
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();
       } 
        */
    }   
}
翻译.java
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"
    }
}
如果不允许我获得如此多的帮助,有人可以告诉我可以允许我发布此请求的其他网站吗?