Spanish Vocabulary Helper
bear
black
blue
cat
cow
dog
fall
gray
green
purple
red
spring
summer
to be
to be able
to go
to love
winter
white
yellow
oso
negro
azul
gato
vaca
perro
otono
gris
verde
morado
rojo
primavera
verano
ser
poder
ir
amar
invierno
blanco
amarillo
Starter Code
/**
* @author
* @author
* CIS 36B
*/
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
public class Translator {
public static void main(String[] args) throws
IOException {
System.out.println("Welcome to the Spanish Vocabulary
Builder!");
String choice = "",
word1 = "", word2 = "";
int pos = -1;
}
}
/**
* Inserts a String element into an array
at a specified index
* @param array the list of String
values
* @param numElements the current number of
elements stored
* @indexToInsert the location in the array
to insert the new element
* @param newValue the new String value to
insert in the array
*/
public static void insert(String array[], int
numElements,
int indexToInsert, String newValue) {
}
/**
* Removes a String element from an array
at a specified index
* @param array the list of String
values
* @param numElements the current number of
elements stored
* @param indexToRemove where in the array
to remove the element
*/
public static void remove(String array[], int
numElements, int indexToRemove) {
}
/**
* Prints an arrays of Strings to the
console
* in the format #. word
* @param words the list of words in
English
* @param numElements the current number of
elements stored
*/
public static void printArrayConsole(String[]
words, int numElements) {
}
/**
* Prints two arrays of Strings to a
file
* in the format #. english word: spanish
word
* @param english the list of words in
English
* @param spanish the list of corresponding
translations in Spanish
* @param numElements the current number of
elements stored
* @param file the file name
*/
public static void printArraysFile(String[]
english, String[] spanish,
int numElements, String fileName) throws IOException {
}
/**
* Searches for a specified String in a
list
* @param array the array of Strings
* @param value the String to search for
* @param numElements the number of elements in
the list
* @return the index where value is located in
the array
*/
public static int linearSearch(String array[], String
value, int numElements) {
return -1;
}
}
Sample Output
Welcome to the Spanish Vocabulary Builder!
Below are the words in English:
0. bear
1. black
2. blue
3. cat
4. cow
5. dog
6. fall
7. gray
8. green
9. purple
10. red
11. spring
12. summer
13. to be
14. to be able
15. to go
16. to love
17. winter
18. white
19. yellow
Please select a menu option below (1-4):
1. Add a new word
2. Remove a word
3. View a word's translation
4. Quit
Enter your choice: 10
That menu option is invalid. Please try again.
Contents of corresponding output file:
0. bear: oso
1. black: negro
2. blue: azul
3. book: libro
4. cat: gato
5. cow: vaca
6. dog: perro
7. fall: otono
8. funny: chistoso
9. gray: gris
10. green: verde
11. purple: morado
12. red: rojo
13. spring: primavera
14. summer: verano
15. to be: ser
16. to go: ir
17. to love: amar
18. winter: invierno
19. white: blanco
20. yellow: amarillo
What to Submit:
Hi, The class you gave has compile errors hence i could not use that. Please find full functionality below.
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
class Scratch {
public static void main(String[] args) throws IOException {
File englishFile = new File("pathtoenglishfile");
File frenchFile = new File("pathtospanishfile");
String arrayEnglish[] = new String[1000];
String arraySpanish[] = new String[1000];
List<String> strings = Files.readAllLines(englishFile.toPath());
int lenEnglishArr, lenSpanishArr;
for (lenEnglishArr = 0; lenEnglishArr < strings.size(); lenEnglishArr++) {
arrayEnglish[lenEnglishArr] = strings.get(lenEnglishArr);
}
strings = Files.readAllLines(frenchFile.toPath());
for (lenSpanishArr = 0; lenSpanishArr < strings.size(); lenSpanishArr++) {
arraySpanish[lenSpanishArr] = strings.get(lenSpanishArr);
}
boolean loop = true;
Scanner sc = new Scanner(System.in);
do {
System.out.println("Add a new word and its translation (choice 1)\n" +
"Remove a word and its translation (choice 2)\n" +
"Display the Spanish translation of an English word (choice 3)\n" +
"Quit (choice 4)");
int choice = sc.nextInt();
if (choice == 1) {
System.out.println("Enter the english word");
String english, french;
english = sc.next();
System.out.println("Enter french word translation");
french = sc.next();
arrayEnglish[lenEnglishArr++] = english;
arraySpanish[lenSpanishArr++] = french;
} else if (choice == 2) {
for (int j = 0; j < lenEnglishArr; j++) {
System.out.println(arrayEnglish[lenEnglishArr] + " - " + arraySpanish + " - " + (lenEnglishArr + 1) + " to remove this translation");
}
int indexCh = sc.nextInt();
for (int j = indexCh - 1; j < 999; j++) {
arrayEnglish[j] = arrayEnglish[j + 1];//moving words up
arraySpanish[j] = arraySpanish[j + 1];
}
lenSpanishArr--;
lenEnglishArr--;
arrayEnglish[indexCh - 1] = "";
arraySpanish[indexCh - 1] = "";
} else if (choice == 3) {
System.out.println("Enter the english word");
String word = sc.next();boolean found=false;
for (int i = 0; i < lenEnglishArr; i++) {
if (arrayEnglish[i].equals(word)) {
System.out.println("Translation is " + arraySpanish[i]);
found=true;
break;
}
}
if(!found){
System.out.println("Not found");
}
} else if (choice == 4) {
System.out.println("Print the name of the file to export words,wo extension");
String str = sc.next();
// File file = Paths.get("").toFile();
System.out.println();
PrintWriter pw = new PrintWriter(new File(System.getProperty("user.dir")+"/"+str+".txt"));
String s="";
for (int i = 0; i < lenEnglishArr; i++) {
s+=arrayEnglish[i]+"\n";
}
s+="\n\n";
for (int i = 0; i < lenSpanishArr; i++) {
s += arraySpanish[i] + "\n";
}
pw.write(s);
pw.flush();
pw.close();
break;
}else{
System.out.println("Choice incorrect try again:");
}
}while(loop);
}
}
Sample out:

Sample out: New word is also added, simple not shown. Everything is working great.

Add a new word and its translation (choice 1), Remove a word and its translation (choice 2) Display the Spanish translation of an English word (choice 3) Quit (choice 4) Enter the english word nice Enter french word translation bega Add a new word and its translation (choice 1), Remove a word and its translation (choice 2), Display the Spanish translation of an English word (choice 3), Quit (choice 4) Enter the english word nice Translation is bega Add a new word and its translation (choice 1), Remove a word and its translation (choice 2), Display the Spanish translation of an English word (choice 3), Quit (choice 4) Print the name of the file to export words, wo extension asdffds Process finished with exit code 0
asdf.txt bear black blue cat COW dog fall gray green purple red spring summer to be to be able to go to love winter white yellow oso negro azul gato vaca perro otono gris verde morado rojo primavera verano ser poder amar invierno blanco amarillo
Spanish Vocabulary Helper For this assignment, we are going to work with adding and removing data...
Modification of original code so it can include 1) at least one array 2)*New English words that are written/saved to the .txt file(s) must be in alphabetical order* (e.g, Apple cannot be in a lower line than Orange). This is what I'm really struggling with as I don't know how to organize alphabetically only the english word translation without the spanish equivalent word also getting organized. The only idea I have right now is to recreate the code using two...
/* * Purpose: Test an implementation of an array-based list ADT. * To demonstrate the use of "ListArrayBased" the project driver * class will populate the list, then invoke various operations * of "ListArrayBased". */ import java.util.Scanner; public class ListDriver { /* * main * * An array based list is populated with data that is stored * in a string array. User input is retrieved from that std in. * A text based...
Assignment #2: List - Array Implementation Review pages 6-7 in "From Java to C++" notes. Due Friday, February 9th, 2017 @ 11:59PM EST Directions Create a List object. Using the following definition (List.h file is also in the repository for your convenience) for a list, implement the member functions (methods) for the List class and store the implementation in a file called List.cpp. Use an array to implement the list. Write the client code (the main method and other non-class...
Trying to practice this assignment Argument list: the *yahoonews.txt Data file: yahoonews.txt Write a program named WordCount.java, in this program, implement two static methods as specified below: public static int countWord(Sting word, String str) this method counts the number of occurrence of the word in the String (str) public static int countWord(String word, File file) This method counts the number of occurrence of the word in the file. Ignore case in the word. Possible punctuation and symbals in the file...
In this lab, you will create a program to help travelers book flights and hotel stays that will behave like an online booking website. The description of the flights and hotel stays will be stored in two separate String arrays. In addition, two separate arrays of type double will be used to store the prices corresponding to each description. You will create the arrays and populate them with data at the beginning of your program. This is how the arrays...
I’m giving you code for a Class called GenericArray, which is an array that takes a generic object type. As usual this is a C# program, make a new console application, and for now you can stick all of this in one big file. And a program that will do some basic stuff with it Generic Array List What I want you to do today: Create methods for the GenericArray, Easy(ish): public void Append (T, value) { // this should...
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...
Need help coding this List. Lists are a lot like arrays, but you’ll be using get, set, add, size and the like instead of the array index operators []. package list.exercises; import java.util.List; public class ListExercises { /** * Counts the number of characters in total across all strings in the supplied list; * in other words, the sum of the lengths of the all the strings. * @param l a non-null list of strings ...
The following code skeleton contains a number of uncompleted methods. With a partner, work to complete the method implementations so that the main method runs correctly: /** * DESCRIPTION OF PROGRAM HERE * @author YOUR NAME HERE * @author PARTNER NAME HERE * @version DATE HERE * */ import java.util.Arrays; import java.util.Random; import java.util.Scanner; public class ArrayExercises { /** * Given a random number generator and a length, create a new array of that * length and fill it from...
Goal: design and implement a dictionary. implement your dictionary using AVL tree . Problem: Each entry in the dictionary is a pair: (word, meaning). Word is a one-word string, meaning can be a string of one or more words (it’s your choice of implementation, you can restrict the meaning to one-word strings). The dictionary is case-insensitive. It means “Book”, “BOOK”, “book” are all the same . Your dictionary application must provide its operations through the following menu (make sure that...