Package lesson05

Source Code of lesson05.TranslatorController

package lesson05;

import lesson05.source.SourceLoader;
import lesson05.source.URLSourceProvider;

import java.io.IOException;
import java.util.Scanner;

public class TranslatorController {

    public static void main(String[] args) throws IOException {

        //initialization

        SourceLoader sourceLoader = new SourceLoader();
        Translator translator = new Translator(new URLSourceProvider());

        Scanner scanner = new Scanner(System.in);
        System.out.println("Type <exit> or enter the path to a file that need to be translated: ");
        String command = scanner.next();

        while (!"exit".equals(command)) {

            //      So, the only way to stop the application is to do that manually or type "exit"
            // paths:
            // /home/av/Downloads/1.txt
            // https://dl.dropboxusercontent.com/u/14434019/en.txt

            try {
                String source = sourceLoader.loadSource(command);
                String translation = translator.translate(source);

                System.out.println("Original: " + source);
                System.out.println("Translation: " + translation);

                System.out.println("Type <exit> or enter the path to a file that need to be translated: ");
                command = scanner.next();

            } catch (IOException e) {
                System.out.println("Incorrect input. Check and try once more or type <exit>: ");
                command = scanner.next();
            } catch (NullPointerException e) {
                System.out.println("Incorrect input. Check and try once more or type <exit>: ");
                command = scanner.next();
            }
        }
    }
}
TOP

Related Classes of lesson05.TranslatorController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.