Package com.geekhub.lessons.lessonFive

Source Code of com.geekhub.lessons.lessonFive.TranslatorController

package com.geekhub.lessons.lessonFive;

import com.geekhub.lessons.lessonFive.sourse.SourceLoader;
import com.geekhub.lessons.lessonFive.sourse.URLSourceProvider;

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

public class TranslatorController {

    public static void main(String[] args) throws IOException {
        SourceLoader sourceLoader = new SourceLoader();
        Translator translator = new Translator(new URLSourceProvider());
        System.out.println("Input source to translate or type 'exit' to exit...");
        Scanner scanner = new Scanner(System.in);
        String command = scanner.next();
        while (!"exit".equals(command)) try {
            String source = sourceLoader.loadSource(command);
            String translate = translator.translate(source);
            System.out.println("English text: \n" + source);
            System.out.println("Russian translation: \n" + translate);
            System.out.println("Input source to translate or type 'exit' to exit...");
            command = scanner.next();
        } catch (IOException | NullPointerException e) {
            System.out.println("Error occurred... Please try once more...");
            System.out.println("Input source to translate or type 'exit' to exit...");
            command = scanner.next();
        }
    }
}
TOP

Related Classes of com.geekhub.lessons.lessonFive.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.