Could you guys write an efficient java program to implement BST.
Your java program should read words and its corresponding French
and store it in a BST. Then read every English word
and print its corresponding French by searching in BST. Assume your
java program is in
xxxxx5.java file (5th java project), where xxxxx is the first 5
characters of your last name.
To compile: javac xxxxx5.java
To execute: java xxxxx5 < any data file name
Your main method should be as follow:
public static void main(String args[]) {
xxxxx5 bst = new xxxxx5 (); // xxxxx is the first 5 characters of
your last name
try{
Scanner inf = new Scanner (System.in);
// Read input from KB/ File
// read no. of words
n = inf.nextInt();
for (i = 1; i <= n; i++){
// read English word
english = inf.next();
// read corresponding word
french = inf.next();
bst.insert(english, french);
}
while(inf.hasNext()){
// read next English word
english = inf.next();
search in BST and print its corresponding French if exist.
}// end while
inf.close();// close input file
}catch (Exception e) {prt("\nException " + e + "\n");}
}// end main method
Sample data file can be as follow:
5 student etudiant book livre this cette is est a une this is a
book
Hi,
Please find below code for your reference. Also I have attached Program and Output screenshots.
Code:-
import java.util.Scanner;
public class TreeNode {
private TreeNode right;
private TreeNode left;
private String english;
private String french;
public TreeNode(String s, String d) {
english = s;
french = d;
}
public String find (String s) {
if (s.equals(english)) {
return
french;
}
if (s.compareTo(english) < 0)
{
if (right !=
null)
return right.find(s);
return "";
}
else {
if (left != null)
return
left.find(s);
return "";
}
}
public void insert (String s, String d) {
if (s.equals(english)) {
french =
d;
return;
}
if (s.compareTo(english) < 0)
{
if (right !=
null)
right.insert(s,d);
else
right = new TreeNode(s,d);
return;
}
if (left != null)
left.insert(s,d);
else
left = new
TreeNode(s,d);
}
public static void main(String args[])
{
TreeNode tn = new TreeNode("English","French");
Scanner inf = new Scanner (System.in);
int n = inf.nextInt();
for(int i=1;i<=n;i++)
{
String english = inf.next();
String french = inf.next();
tn.insert(english,french);
}
while (inf.hasNext())
{
String english = inf.next();
System.out.println("English->"+english);
String french = tn.find(english);
System.out.println("French->"+french);
}
inf.close();
}
}





Could you guys write an efficient java program to implement BST. Your java program should read...
Write an efficient java program to implement BST. Your java program should read n words and its corresponding French and store it in a BST. Then read every English word and print its corresponding French by searching in BST. Assume your java program is in engtofren.java file To compile: javac engtofren.java To execute: java engtofren< any data file name Your main method should be as follow: public static void main(String args[]) { engtofren bst = new engtofren (); // try{...
Write a java program to convert and print an infix expression to postfix expression. You can use Java stack methods. (Must read input from System.in) Your main method should be as follow: public static void main(String args[]) { intopost p = new intopost (); String iexp, pexp; //infix postfix expression try{ Scanner inf = new Scanner (System.in); // Read input from KB/ File while(inf.hasNext()){ // read next infix expression iexp = inf.next(); // Assume method name to convert infix...
Write a Python program to read lines of text from a file. For each word (i.e, a group of characters separated by one or more whitespace characters), keep track of how many times that word appears in the file. In the end, print out the top twenty counts and the corresponding words for each count. Print each value and the corresponding words, in alphabetical order, on one line. Print this in reverse sorted order by word count. You can assume...
Could I get some help with this assignment In this assignment, you'll write a program which reads a text file, and prints a histogram of its word sizes. So, for example, the historgram should show the number of words of length 1, of length 2, etc., up to the number of words of length n, where n is some constant defined in your program. To obtain text files that are suitably long, you could try Project Gutenberg, a site containing...
In this assignment you will implement the second version of your spell checker. Using the randomized dictionary (random_dictionary.txt) given, read in the dictionary into an array of 26 Binary Search Trees (BST) , one for each letter of the alphabet. Thus the first BST would contain only those words starting with letter 'a', while the last would contain only those words starting with letter 'z'. Then, when you read in the book (oliver.txt), you examine the first character of each...
In this assignment you will implement the second version of your spell checker. Using the randomized dictionary (random_dictionary.txt) given, read in the dictionary into an array of 26 Binary Search Trees (BST) , one for each letter of the alphabet. Thus the first BST would contain only those words starting with letter 'a', while the last would contain only those words starting with letter 'z'. Then, when you read in the book (oliver.txt), you examine the first character of each...
4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java source code file named H01_43.java (your main class is named H01_43). Problem: Write a program that prompts the user for the name of a Java source code file (you may assume the file contains Java source code and has a .java filename extension; we will not test your program on non-Java source code files). The program shall read the source code file and output...
For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...
Write a French/English dictionary lookup program. Read a list of pairs of English and French words from a file specified by the user. English/French words should be exact matches (don't try to find partial matches). Use the supplied EnglishFrenchDictionary.java class as your main class. Fill in the missing code in the DictionaryTable.java class to read the input file and perform the searches. Add code to the DictionaryTable read() method to: read pairs of lines (English word is on the first...
Write a simple program in Java or C, that will help you to figure out the key used for Vigenère encrypted file. For this exercise, assume the key length is less than five characters long and only English upper case letters from A-Z are used. You may also assume the plaintext contains only the upper case English letters from A-Z, ignore the space characters. Your program should take a ciphertext file (encrypted using the Vigenère encryption algorithm) as input and...