Ver Mensaje Individual
  #5 (permalink)  
Antiguo 21/01/2012, 11:35
moltimix
 
Fecha de Ingreso: agosto-2007
Mensajes: 25
Antigüedad: 16 años, 8 meses
Puntos: 0
Respuesta: Dudas con Hashtable

No sé si será problema de mi compilador: JCreator LE


Adjunto los fuentes. Con esto pretendo añadir que pida al usuario por teclado el nombre del idioma y muestre el nombre de los meses y dias de la semana en su correspondiente idioma.


CalendariosBiligunes.java

Código Javascript:
Ver original
  1. import java.io.*;
  2. import java.util.*;
  3. import javagently.*;
  4.  
  5. public class CalendariosBilingues {
  6.    
  7.     /**
  8.      * Method main
  9.      *
  10.      * @param args
  11.      *
  12.      */
  13.      
  14.     static final int noDeIdiomas = 2;
  15.     static final int noMeses = 12;
  16.     static final int noDias = 7;
  17.    
  18.     public static void main(String[] args) throws IOException {
  19.         // TODO: Add your code here
  20.    
  21.         String meses[] = new String [noMeses];
  22.         String dias[] = new String [noDias];
  23.    
  24.    
  25.        
  26.         BufferedReader fin = Text.open("entrada.txt");
  27.         BufferedReader in = Text.open(System.in);
  28.         Hashtable<String,String[]> tablaMes = new Hashtable<String,String[]>();
  29.         Hashtable<String,String[]> tablaDia = new Hashtable<String,String[]>();
  30.        
  31.        
  32.         System.out.println("CALENDARIOS BILINGUES");
  33.         System.out.println("=====================");
  34.        
  35.         //Declaro dos Hashtables, una para los meses y otra para los días de la semana
  36.         //Voy rellenando ambas tablas con los datos del fichero
  37.         for(int i=0;i<noDeIdiomas;i++){
  38.             Calendario cal = new Calendario();
  39.             cal.ponerIdioma(fin);
  40.            
  41.             for(int j=0;j<noMeses;j++){
  42.                 cal.ponerLiteralMeses(fin);
  43.                 meses[j] = cal.literalMes;
  44.             }
  45.             tablaMes.put(cal.idioma,meses);
  46.            
  47.             for(int j=0;j<noDias;j++){
  48.                 cal.ponerLiteralDias(fin);
  49.                 dias[j] = cal.literalDia;
  50.             }
  51.             tablaDia.put(cal.idioma,dias);
  52.         }
  53.        
  54.         //Muestro en pantalla los datos leidos     
  55.         System.out.println("Idioma\t\tMeses");
  56.         for(Enumeration e = tablaMes.keys();e.hasMoreElements();){
  57.             String idioma = (String)e.nextElement();
  58.            
  59.             String meses_nom[] = new String [noMeses];
  60.             meses_nom= tablaMes.get(idioma);
  61.  
  62.             for(int i=0;i<noMeses;i++){
  63.                 System.out.println(idioma+"\t\t"+meses_nom[i]); //Muestra idioma tabulado con el nombre del mes
  64.             }
  65.         }
  66.        
  67.         System.out.println();  
  68.     }  
  69. }

Calendarios.java
Código Javascript:
Ver original
  1. import java.io.*;
  2. import java.util.*;
  3. import javagently.*;
  4.  
  5. public class Calendario {
  6.    
  7.     String idioma, literalMes, literalDia;
  8.  
  9.    
  10.     public Calendario(){}
  11.    
  12.     void ponerIdioma(BufferedReader fin) throws IOException {
  13.         idioma = Text.readString(fin);
  14.         System.out.println("Idioma: "+idioma);
  15.        
  16.     }
  17.    
  18.     void ponerLiteralMeses(BufferedReader fin) throws IOException {
  19.         literalMes = Text.readString(fin);
  20.         System.out.println("literalMes: "+literalMes);
  21.     }
  22.    
  23.     void ponerLiteralDias(BufferedReader fin) throws IOException {
  24.         literalDia = Text.readString(fin);
  25.         System.out.println("literalDia: "+literalDia);
  26.     }      
  27. }