Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Interfaz Traducible
- package apliinterfaces2;
- public interface Traducible {
- String[] words = {"hello","goobay","How are you?","I´m fine","What´s your name"};
- String[] mots = {"salut","Au revoir","comment ça va","je vais bien","comment tu t'apelles"};
- String[] parole = {"ciao","addio","come stai","Io sto bene","Il tuo nome"};
- String alIngles();
- String alFrances();
- String alItaliano();
- }
- //Fin interfaz
- package apliinterfaces2;
- import java.util.Scanner;
- public class ApliInterfaces2 {
- public static void main(String[] args) {
- Scanner lector = new Scanner(System.in);
- Documento d;
- String palabra;
- int op;
- boolean fin = false;
- while(!fin){
- System.out.print("Palabra o frase a traducir: ");
- palabra = lector.nextLine();
- d = new Documento(palabra);
- op = menu();
- switch(op){
- case 1: System.out.println(d.alIngles());
- pausa();
- break;
- case 2: System.out.println(d.alFrances());
- pausa();
- break;
- case 3: System.out.println(d.alItaliano());
- pausa();
- break;
- case 4: fin = true;
- break;
- default: System.out.println("No has elegido una opción válida");
- pausa();
- break;
- }
- }
- }
- public static void pausa(){
- Scanner lector = new Scanner(System.in);
- System.out.println("Pulsa intro para continuar.....");
- lector.nextLine();
- }
- public static int menu(){
- Scanner lector = new Scanner(System.in);
- int op;
- System.out.println("********* MENU **********");
- System.out.println("1. Traducir al inglés");
- System.out.println("2. Traducir al francés");
- System.out.println("3. Traducir al italiano");
- System.out.println("4. Salir");
- System.out.print("Elije opción: ");
- op = lector.nextInt();
- return op;
- }
- }
- class Documento implements Traducible{
- private String texto;
- public Documento(String texto) {
- this.texto = texto;
- }
- public String getTexto() {
- return texto;
- }
- public void setTexto(String texto) {
- this.texto = texto;
- }
- public String alIngles() {
- String textoTraducido;
- texto = texto.toLowerCase();
- switch(texto){
- case "hola": textoTraducido = words[0];
- break;
- case "adiós": textoTraducido = words[1];
- break;
- case "cómo estás": textoTraducido = words[2];
- break;
- case "estoy bien": textoTraducido = words[3];
- break;
- case "cómo te llamas": textoTraducido = words[4];
- break;
- default: textoTraducido = "I can not give you a translation for this text";
- break;
- }
- return "En inglés: " + textoTraducido;
- }
- public String alFrances() {
- String textoTraducido;
- texto = texto.toLowerCase();
- switch(texto){
- case "hola": textoTraducido = mots[0];
- break;
- case "adiós": textoTraducido = mots[1];
- break;
- case "cómo estás": textoTraducido = mots[2];
- break;
- case "estoy bien": textoTraducido = mots[3];
- break;
- case "cómo te llamas": textoTraducido = mots[4];
- break;
- default: textoTraducido = "Je ne peux pas donner la traduction de ce texte";
- break;
- }
- return "En francés: " + textoTraducido;
- }
- public String alItaliano() {
- String textoTraducido;
- texto = texto.toLowerCase();
- switch(texto){
- case "hola": textoTraducido = parole[0];
- break;
- case "adiós": textoTraducido = parole[1];
- break;
- case "cómo estás": textoTraducido = parole[2];
- break;
- case "estoy bien": textoTraducido = parole[3];
- break;
- case "cómo te llamas": textoTraducido = parole[4];
- break;
- default: textoTraducido = "Non posso dare una traduzione per questo testo";
- break;
- }
- return "En italiano: " + textoTraducido;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement