Question: Implementation in java using a 2d array: Another chegg tutor answered my previous question, but I managed to fix all but one part of his

Implementation in java using a 2d array: Another chegg tutor answered my previous question, but I managed to fix all but one part of his code. Specifically, String a[][] = new int[10000][2]; incompatible types: int[] cannot be converted to String [][]

https://www.chegg.com/homework-help/questions-and-answers/modification-original-code-include-1-least-one-array-2-new-english-words-written-saved-txt-q29344880?trackid=6d1b82e0&strackid=24ee7d8b&ii=1

The full code that was posted was this with some obvious mistypes import java.io.*; import java.util.HashMap; import java.util.Map; import java.util.Scanner;

//*SECOND CLASS

class FlashCard { private String englishWord; private String spanishWord;

//arg constructor public FlashCard(String enWord,String esWord) { this.englishWord=enWord; this.spanishWord=esWord; }

/** * @return the englishWord */ public String getEnglishWord() { return englishWord; }

/** * @param englishWord the englishWord to set */ public void setEnglishWord(String englishWord) { this.englishWord = englishWord; }

/** * @return the spanishWord */ public String getSpanishWord() { return spanishWord; }

/** * @param spanishWord the spanishWord to set */ public void setSpanishWord(String spanishWord) { this.spanishWord = spanishWord; }

}

//*THIRD CLASS*

class EnglishOptions { private String enToEs; private String esToEn; private String enterEnWord; private String enterEsWord; private String successMessage; private String wordPrompt; public EnglishOptions() { this.enterEnWord="Enter english word"; this.enterEsWord="Enter spanish word"; this.enToEs="Enter 1 for English to Spanish"; this.esToEn="Enter 2 for Spanish to English"; this.successMessage="Flash Card added sucessfully!"; this.wordPrompt="Enter the word"; } /** * @return the enterEnWord */ public String getEnterEnWord() { return enterEnWord; } /** * @return the enterEsWord */ public String getEnterEsWord() { return enterEsWord; }

/** * @return the enToEs */ public String getEnToEs() { return enToEs; }

/** * @return the esToEn */ public String getEsToEn() { return esToEn; } public String getsuccessMessage() { return successMessage; }

public String getWordPrompt() { return wordPrompt; } }

public class Translation { public static void main(String[] args) throws IOException {

// the size of the array can be any large number/ String a[][] = new int[10000][2]; // creating an array as per the requirement which will be used to store and sort the set of // English- Spanish pairs in the text file. String english,spanish; int choice=0; Scanner in = new Scanner(System.in); Scanner inString = new Scanner(System.in); String line; File file = new File("Dictionary.txt"); Scanner reader = new Scanner(file); int cnt = 0; // to store the number of rows in a dictionary while (reader.hasNextLine()) { line = reader.nextLine(); FlashCard fcard=new FlashCard(line.split(" ")[0],line.split(" ")[1]); a[cnt][0] = line.split(" ")[0]; // populating the array with english word a[cnt][1] = line.split(" ")[1]; // populating the array with spanish word cnt++; // incrementing the count } System.out.println("Data loaded successfully"); reader.close(); EnglishOptions eo=new EnglishOptions(); while(choice!=3){ System.out.println("Enter 1 to add word Enter 2 to search word Enter 3 to store data and quit"); choice = in.nextInt(); if(choice==1){ System.out.println(eo.getEnterEnWord()); english=inString.nextLine(); System.out.println(eo.getEnterEsWord()); spanish=inString.nextLine(); FlashCard card=new FlashCard(english,spanish); a[cnt][0] = english; // adding 1 more english word in the array a[cnt][1] = spanish; // adding 1 more spanish words in the array System.out.println(eo.getsuccessMessage()); }else if(choice==2){ System.out.println(eo.getEnToEs() + " " +eo.getEsToEn()); int lang = in.nextInt(); System.out.println(eo.getWordPrompt());

String wordSearch = inString.nextLine(); if(lang==1){ for(int i = 0;i

} else if(lang==2){

boolean found= false; String result="";

for(int i = 0;i

if(found){ System.out.println(wordSearch +" in English is "+result); }else{ System.out.println(wordSearch+" not found!"); } } } else if(choice==3){ // overriding the compare method of Comparator interface. Arrays.sort(a, new Comparator(){ @Override public int compare(String[] s1, String[] entry2) { String e1 = s1[0]; // getting the english word from one row String e2 = s1[0]; // getting the english word from another row return e1.compareToIgnoreCase(e2); // this method return positive number if e1 > e2 , // return negative if e1 < e2, all the comparison is done lexicographically } }); FileWriter out =new FileWriter("Dictionary.txt"); for(String[] engl_span : a) { out.write(engl_span[0]+ " "+engl_span[1] +" "); } out.close(); out.close(); } } in.close(); inString.close(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!