// TranslateOLD.java (c) 2002 Kari Laitinen // www.naturalprogramming.com // 2005-05-03 File created. // 2005-05-03 Last modification. // An older version of the Translate.java program. import java.util.ArrayList ; class BilingualTranslation { protected String first_word ; protected String second_word ; public BilingualTranslation() {} public BilingualTranslation( String given_first_word, String given_second_word ) { first_word = given_first_word ; second_word = given_second_word ; } public boolean translate( String given_word ) { boolean translation_was_successful = false ; if ( given_word.equals( first_word ) ) { System.out.print( "\n \"" + given_word + "\" translates to \"" + second_word + "\"" ) ; translation_was_successful = true ; } if ( given_word.equals( second_word ) ) { System.out.print( "\n \"" + given_word + "\" translates to \"" + first_word + "\"" ) ; translation_was_successful = true ; } return translation_was_successful ; } } class TrilingualTranslation extends BilingualTranslation { protected String third_word ; public TrilingualTranslation( String given_first_word, String given_second_word, String given_third_word ) { first_word = given_first_word ; second_word = given_second_word ; third_word = given_third_word ; } public boolean translate( String given_word ) { boolean translation_was_successful = false ; if ( given_word.equals( first_word ) ) { System.out.print( "\n \"" + given_word + "\" translates to \"" + second_word + "\" and \"" + third_word + "\"" ) ; translation_was_successful = true ; } if ( given_word.equals( second_word ) ) { System.out.print( "\n \"" + given_word + "\" translates to \"" + first_word + "\" and \"" + third_word + "\"" ) ; translation_was_successful = true ; } if ( given_word.equals( third_word ) ) { System.out.print( "\n \"" + given_word + "\" translates to \"" + first_word + "\" and \"" + second_word + "\"" ) ; translation_was_successful = true ; } return translation_was_successful ; } } class TranslateOLD { public static void main( String[] command_line_parameters ) { if ( command_line_parameters.length == 1 ) { ArrayList array_of_translations = new ArrayList() ; array_of_translations.add( new BilingualTranslation( "week", "semana" ) ) ; array_of_translations.add( new TrilingualTranslation( "street", "calle", "rue" ) ) ; array_of_translations.add( new BilingualTranslation( "eat", "comer" ) ) ; array_of_translations.add( new TrilingualTranslation( "woman", "mujer", "femme" ) ) ; array_of_translations.add( new TrilingualTranslation( "man", "hombre", "homme" ) ) ; array_of_translations.add( new BilingualTranslation( "sleep", "dormir" ) ) ; int translation_index = 0 ; while ( translation_index < array_of_translations.size() ) { ( ( BilingualTranslation ) array_of_translations.get( translation_index ) ). translate( command_line_parameters[ 0 ] ) ; translation_index ++ ; } System.out.print( "\n" ) ; } else { System.out.print( "\n Give a word on command line.\n\n" ) ; } } }