Lab 2: Working with Arrays (100 pts)Due Monday, April 27 at 11:59pm on CanvasPair Programming Required (or No Credit)
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. 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: 1 Enter the word to add in English: book Enter book's Spanish translation: libro Enter the alphabetical position in the list for book(0-20): 3 Below are the words in English: 0. bear 1. black 2. blue 3. book 4. cat 5. cow 6. dog 7. fall 8. gray 9. green 10. purple 11. red 12. spring 13. summer 14. to be 15. to be able 16. to go 17. to love 18. winter 19. white 20. 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: 3 Enter the word in English: golf Sorry! That word does not exist in this dictionary. Below are the words in English: 0. bear 1. black 2. blue 3. book 4. cat 5. cow 6. dog 7. fall 8. gray 9. green 10. purple 11. red 12. spring 13. summer 14. to be 15. to be able 16. to go 17. to love 18. winter 19. white 20. 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: 3 Enter the word in English: book book = libro Below are the words in English: 0. bear 1. black 2. blue 3. book 4. cat 5. cow 6. dog 7. fall 8. gray 9. green 10. purple 11. red 12. spring 13. summer 14. to be 15. to be able 16. to go 17. to love 18. winter 19. white 20. 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: 1 Enter the word to add in English: funny Enter funny's Spanish translation: chistoso Enter the alphabetical position in the list for funny(0-21): 8 Below are the words in English: 0. bear 1. black 2. blue 3. book 4. cat 5. cow 6. dog 7. fall 8. funny 9. gray 10. green 11. purple 12. red 13. spring 14. summer 15. to be 16. to be able 17. to go 18. to love 19. winter 20. white 21. 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: 2 Enter the word to remove: scarf Sorry! That word does not exist in this dictionary. Below are the words in English: 0. bear 1. black 2. blue 3. book 4. cat 5. cow 6. dog 7. fall 8. funny 9. gray 10. green 11. purple 12. red 13. spring 14. summer 15. to be 16. to be able 17. to go 18. to love 19. winter 20. white 21. 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: 2 Enter the word to remove: to be able Below are the words in English: 0. bear 1. black 2. blue 3. book 4. cat 5. cow 6. dog 7. fall 8. funny 9. gray 10. green 11. purple 12. red 13. spring 14. summer 15. to be 16. to go 17. to love 18. winter 19. white 20. 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: 5 That menu option is invalid. Please try again. Below are the words in English: 0. bear 1. black 2. blue 3. book 4. cat 5. cow 6. dog 7. fall 8. funny 9. gray 10. green 11. purple 12. red 13. spring 14. summer 15. to be 16. to go 17. to love 18. winter 19. white 20. 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: 4 Enter the name of the output file: translations.txt You may now open translations.txt to view the translations. Goodbye! 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
How You Will Be Graded:
|