0

What did I do wrong in DictionBin.translate(B)? No translation is happening. I’m getting “No comprehendo”

In the class DictionBin, the method translateB uses a binary search to search for a string in the dictionary. If found, the associated data value is returned, otherwise the string “No Comprehendo” is returned. DictionBin extends DictionBase. In DictionBase, the value returned from getKey is the english word at the position and the value returned from getVal is the spanish word at the position. https://code.sololearn.com/cu8xmK6VQOm7/?ref=app

2nd Nov 2022, 5:08 PM
Triz
Triz - avatar
9 Antworten
+ 2
I guess you are not performing a binary search on a 2d array, but on a 1d subdimension of a multidimensional array? In that case you do your ordinary binary search. It requires the keys to be sorted, of course.
2nd Nov 2022, 9:51 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 1
getVal() is wrong, it looks at first word in dict. only // String val = dictionArr[0][key1]; String val = dictionArr[key1][1];
3rd Nov 2022, 1:12 AM
zemiak
+ 1
try find test.txt manually and look inside or add some print command to display dictionary or BlueJ has debbuger look at main(), this is in tutorial: 9.3 Calling main and other static methods Summary: Static methods can be called from the class's popup menu. Open the hello project from the examples directory. The only class in the project (class Hello) defines a standard main method. Right-click on the class, and you will see that the class menu includes not only the class’s constructor, but also the static main method. You can now call main directly from this menu (without first creating an object). or how you add parameters for execute translate search method ?
3rd Nov 2022, 4:55 AM
zemiak
0
Ani Jona 🕊 I added the code for the binary search but when I run it, no translation is happening. I’m getting “No comprehendo”
2nd Nov 2022, 10:28 PM
Triz
Triz - avatar
0
2nd Nov 2022, 10:30 PM
Triz
Triz - avatar
0
zemiak thank you. I fixed that. However, I’m still getting no comprehende. Could you please take a look at my translate method and let me know if something is incorrect?
3rd Nov 2022, 1:19 AM
Triz
Triz - avatar
0
it works for me, check input, if array is sorted and how you call search method
3rd Nov 2022, 1:21 AM
zemiak
0
zemiak its a bluej program. So all I do is select the dictionary and perform translation using a test.txt file as input. So, i think something is wrong with the code I wrote but I just don’t know what it is. Sigh
3rd Nov 2022, 1:30 AM
Triz
Triz - avatar
0
X bx
3rd Nov 2022, 9:33 PM
Nizar Nana
Nizar Nana - avatar