Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Look over the English to Spanish dictionary (engl2span.txt). The first line i

ID: 3760147 • Letter: 1

Question

1) Look over the English to Spanish dictionary (engl2span.txt). The first line in the file is a value representing the current number of entries in the dictionary.

2) Look over Entry.java (model class) and IO.java (view class). They are already finished for you.

3) In Converter.java (another model class), finish the constructor (see the instructions within the file). Review the ‘translate’ method that is already completed within the Converter class.

4) Finish the Lab9.java class (controller class) which contains ONLY the main method (Again, see the instructions within the file)

please answer the you do this part........ someone save my life please...... help me computer science god!!

import java.util.*;
import java.io.*;

public class Converter {
   private Entry[] dictionary;

   /**
   * Converter loads the English-Spanish dictionary
   *
   * @param filename The filename of the dictionary
   */
   public Converter(String filename) throws IOException {
       Scanner inFile = new Scanner(new File(filename));
       dictionary = new Entry[Integer.parseInt(inFile.nextLine())];
       for (int i = 0; i < dictionary.length; i++) {
           String line = inFile.nextLine();
          
           //YOU DO THIS
           //break line into the English section and the Spanish section
           //the two pieces are separated by a " " character -- use split or StringTokenizer
           //create a new Entry object with the English and Spanish parts,
           //and store it at spot i in the dictionary array
       }
       inFile.close();
   }

   /**
   * translate returns the Spanish translation
   * of english
   *
   * @param english The english word to translate
   * @return The spanish translation, or a message that it couldn't be found
   */
   public String translate(String english) {
       for (int i = 0; i < dictionary.length; i++) {
           if (english.equals(dictionary[i].getEnglish())) {
               return dictionary[i].getSpanish();
           }
       }

       return "Word not in dictionary";
   }
}

/** CONTROLLER
* This program is an English-Spanish translator.
*
* @author
* @version Lab 9
*/
import java.util.*;
import java.io.*;

public class Lab9 {
   /**
   * main handles the control flow for the program
   *
   * @param args Should hold the dictionary filename
   */
   public static void main(String[] args) throws IOException {
       //YOU DO THIS
      
       // get the name of the input file as a command-line argument (should be in args[0])
       // create an IO object
       // create a Converter object and pass to the constructor the name of the input file
      
       // while the user doesn't just press Enter
           // get an English word from the user (call the getWord method in IO)
           // get the Spanish translation for the word (call the translate method in Converter)
           // print the translation (call the printTranslation method in IO)
   }
}

public class Entry {
   private String engl;
   private String span;

   /**
   * Entry sets up a single English-Spanish entry
   *
   * @param english An English word
   * @param spanish The Spanish translation
   */
   public Entry(String e, String s) {
       engl = e;
       span = s;
   }

   /**
   * returns this entry's English word
   *
   * @return This entry's English word
   */
   public String getEnglish() {
       return engl;
   }

   /**
   * returns this entry's Spanish word
   *
   * @return This entry's Spanish word
   */
   public String getSpanish() {
       return span;
   }
}

/** VIEW
* This class handles all input and output for the
* English-Spanish translator.
*
*/

import java.util.*;

public class IO {
   private Scanner s;
  
   public IO() {
       s = new Scanner(System.in);
   }

   /**
   * getWord prompts the user for an English word
   *
   * @return The English word entered by the user
   */
   public String getWord() {
           System.out.print("Enter an English word (press enter to quit): ");
           String word = s.nextLine();
           System.out.println();
           return word;
   }

   /**
   * printTranslation prints an English word and its Spanish translation
   *
   * @param english The English word
   * @param spanish The Spanish word
   */
   public void printTranslation(String english, String spanish) {
       System.out.println(english + ": " + spanish + " ");
   }
}

Explanation / Answer

import java.util.*;
import java.io.*;
public class Converter {
private Entry[] dictionary;
/**
* Converter loads the English-Spanish dictionary
*
* @param filename The filename of the dictionary
*/
public Converter(String filename) throws IOException {
Scanner inFile = new Scanner(new File(filename));
dictionary = new Entry[Integer.parseInt(inFile.nextLine())];
for (int i = 0; i < dictionary.length; i++) {
String line = inFile.nextLine();
  
//YOU DO THIS
//break line into the English section and the Spanish section
//the two pieces are separated by a " " character -- use split or StringTokenizer
//create a new Entry object with the English and Spanish parts,
//and store it at spot i in the dictionary array
}
inFile.close();
}
/**
* translate returns the Spanish translation
* of english
*
* @param english The english word to translate
* @return The spanish translation, or a message that it couldn't be found
*/
public String translate(String english) {
for (int i = 0; i < dictionary.length; i++) {
if (english.equals(dictionary[i].getEnglish())) {
return dictionary[i].getSpanish();
}
}
return "Word not in dictionary";
}
}
/** CONTROLLER
* This program is an English-Spanish translator.
*
* @author
* @version Lab 9
*/
import java.util.*;
import java.io.*;
public class Lab9 {
/**
* main handles the control flow for the program
*
* @param args Should hold the dictionary filename
*/
public static void main(String[] args) throws IOException {
//YOU DO THIS
  
// get the name of the input file as a command-line argument (should be in args[0])
// create an IO object
// create a Converter object and pass to the constructor the name of the input file
  
// while the user doesn't just press Enter
// get an English word from the user (call the getWord method in IO)
// get the Spanish translation for the word (call the translate method in Converter)
// print the translation (call the printTranslation method in IO)
}
}
public class Entry {
private String engl;
private String span;
/**
* Entry sets up a single English-Spanish entry
*
* @param english An English word
* @param spanish The Spanish translation
*/
public Entry(String e, String s) {
engl = e;
span = s;
}
/**
* returns this entry's English word
*
* @return This entry's English word
*/
public String getEnglish() {
return engl;
}
/**
* returns this entry's Spanish word
*
* @return This entry's Spanish word
*/
public String getSpanish() {
return span;
}
}
/** VIEW
* This class handles all input and output for the
* English-Spanish translator.
*
*/
import java.util.*;
public class IO {
private Scanner s;
  
public IO() {
s = new Scanner(System.in);
}
/**
* getWord prompts the user for an English word
*
* @return The English word entered by the user
*/
public String getWord() {
System.out.print("Enter an English word (press enter to quit): ");
String word = s.nextLine();
System.out.println();
return word;
}
/**
* printTranslation prints an English word and its Spanish translation
*
* @param english The English word
* @param spanish The Spanish word
*/
public void printTranslation(String english, String spanish) {
System.out.println(english + ": " + spanish + " ");
}
}