Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.80 KB | None | 0 0
  1. //Interfaz Traducible
  2.  
  3.  
  4. package apliinterfaces2;
  5. public interface Traducible {
  6.     String[] words = {"hello","goobay","How are you?","I´m fine","What´s your name"};
  7.     String[] mots = {"salut","Au revoir","comment ça va","je vais bien","comment tu t'apelles"};
  8.     String[] parole = {"ciao","addio","come stai","Io sto bene","Il tuo nome"};
  9.     String alIngles();
  10.     String alFrances();
  11.     String alItaliano();
  12. }
  13.  
  14. //Fin interfaz
  15.  
  16.  
  17. package apliinterfaces2;
  18. import java.util.Scanner;
  19. public class ApliInterfaces2 {
  20.     public static void main(String[] args) {
  21.        Scanner lector = new Scanner(System.in);
  22.        Documento d;
  23.        String palabra;
  24.        int op;
  25.        boolean fin = false;
  26.        while(!fin){
  27.            System.out.print("Palabra o frase a traducir: ");
  28.            palabra = lector.nextLine();
  29.            d = new Documento(palabra);
  30.            op = menu();
  31.            switch(op){
  32.                case 1: System.out.println(d.alIngles());
  33.                        pausa();
  34.                        break;
  35.                case 2: System.out.println(d.alFrances());
  36.                        pausa();
  37.                        break;
  38.                case 3: System.out.println(d.alItaliano());
  39.                        pausa();
  40.                        break;
  41.                case 4: fin = true;
  42.                        break;
  43.                default: System.out.println("No has elegido una opción válida");
  44.                        pausa();
  45.                        break;
  46.            }
  47.        }
  48.     }
  49.     public static void pausa(){
  50.         Scanner lector = new Scanner(System.in);
  51.        
  52.         System.out.println("Pulsa intro para continuar.....");
  53.         lector.nextLine();
  54.     }
  55.     public static int menu(){
  56.         Scanner lector = new Scanner(System.in);
  57.         int op;
  58.        
  59.         System.out.println("********* MENU **********");
  60.         System.out.println("1. Traducir al inglés");
  61.         System.out.println("2. Traducir al francés");
  62.         System.out.println("3. Traducir al italiano");
  63.         System.out.println("4. Salir");
  64.         System.out.print("Elije opción: ");
  65.         op = lector.nextInt();
  66.         return op;
  67.     }
  68. }
  69. class Documento implements Traducible{
  70.     private String texto;
  71.  
  72.     public Documento(String texto) {
  73.         this.texto = texto;
  74.     }
  75.  
  76.     public String getTexto() {
  77.         return texto;
  78.     }
  79.  
  80.     public void setTexto(String texto) {
  81.         this.texto = texto;
  82.     }
  83.  
  84.     public String alIngles() {
  85.         String textoTraducido;
  86.         texto = texto.toLowerCase();
  87.         switch(texto){
  88.             case "hola": textoTraducido = words[0];
  89.                          break;
  90.             case "adiós": textoTraducido = words[1];
  91.                           break;
  92.             case "cómo estás": textoTraducido = words[2];
  93.                           break;  
  94.             case "estoy bien": textoTraducido = words[3];
  95.                           break;  
  96.             case "cómo te llamas": textoTraducido = words[4];
  97.                           break;    
  98.             default: textoTraducido = "I can not give you a translation for this text";
  99.                           break;
  100.         }
  101.         return "En inglés: " + textoTraducido;
  102.     }    
  103.    
  104.  
  105.    
  106.     public String alFrances() {
  107.         String textoTraducido;
  108.         texto = texto.toLowerCase();
  109.         switch(texto){
  110.             case "hola": textoTraducido = mots[0];
  111.                          break;
  112.             case "adiós": textoTraducido = mots[1];
  113.                           break;
  114.             case "cómo estás": textoTraducido = mots[2];
  115.                           break;  
  116.             case "estoy bien": textoTraducido = mots[3];
  117.                           break;  
  118.             case "cómo te llamas": textoTraducido = mots[4];
  119.                           break;    
  120.             default: textoTraducido = "Je ne peux pas donner la traduction de ce texte";
  121.                           break;
  122.         }
  123.         return "En francés: " + textoTraducido;
  124.     }
  125.  
  126.    
  127.     public String alItaliano() {
  128.         String textoTraducido;
  129.         texto = texto.toLowerCase();
  130.         switch(texto){
  131.             case "hola": textoTraducido = parole[0];
  132.                          break;
  133.             case "adiós": textoTraducido = parole[1];
  134.                           break;
  135.             case "cómo estás": textoTraducido = parole[2];
  136.                           break;  
  137.             case "estoy bien": textoTraducido = parole[3];
  138.                           break;  
  139.             case "cómo te llamas": textoTraducido = parole[4];
  140.                           break;    
  141.             default: textoTraducido = "Non posso dare una traduzione per questo testo";
  142.                           break;
  143.         }
  144.         return "En italiano: " + textoTraducido;
  145.     }
  146.    
  147.    
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement