Question: Can someone help me to write a test case for this code? This what I have. I'm really stuck on this part. Can someone please

Can someone help me to write a test case for this code? This what I have. I'm really stuck on this part. Can someone please help me today? Can someone explain it to me? ASAP?!?!!!!!!

import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Scanner; public class UserInterface { public static void main(String[] args) throws IOException { final int NUM_SONGS = 15; final int NUM_WORDS = 10000; String songName, artist, lyrics; int year, length, id; HashTable songList = new HashTable<>(NUM_SONGS * 2); HashTable wordList = new HashTable<>(NUM_WORDS); ArrayList> searchList = new ArrayList>(); DecimalFormat df = new DecimalFormat("0.00"); File file1 = new File("song_input.txt"); try { Scanner input = new Scanner(file1); while (input.hasNextLine()) { songName = input.nextLine(); artist = input.nextLine(); year = input.nextInt(); length = input.nextInt(); input.nextLine(); lyrics = input.nextLine(); Song tempSong = new Song(songName, artist, year, length, lyrics); String[] words = lyrics.split(" "); for (int i = 0; i < words.length; i++) { if (words[i] != "i" || words[i] != "im" || words[i] != "that" || words[i] != "and" || words[i] != "you" || words[i] != "is" || words[i] != "it" || words[i] != "its" || words[i] != "but" || words[i] != "who" || words[i] != "whos" || words[i] != "so" || words[i] != "with" || words[i] != "me" || words[i] != "in" || words[i] != "on" || words[i] != "a" || words[i] != "go" || words[i] != "to" || words[i] != "how" || words[i] != "all" || words[i] != "like" || words[i] != "up" || words[i] != "got") { if (!wordList.contains(new WordID(words[i], false))) { WordID newWord = new WordID(words[i], true); wordList.put(newWord); } id = wordList.get(new WordID(words[i], false)).getID(); while (searchList.size() <= id) { searchList.add(new BST()); } if (searchList.get(id).search(tempSong, false, new NameComparator()) == null) { searchList.get(id).insert(tempSong, new NameComparator()); } } } tempSong.setLyrics(lyrics); songList.put(tempSong); input.nextLine(); } input.close(); input = new Scanner(System.in); System.out.println("Welcome to Team 1's search engine!"); char userinput = ' '; while (userinput != 'X') { System.out.println(" Please select from the following options: "); System.out.println("A. Upload a Record"); System.out.println("B. Delete a Record"); System.out.println("C. Search for a Record"); System.out.println("D. Modify/Update a Record"); System.out.println("E. Statistics"); System.out.println("X. Exit "); System.out.print("Enter your choice: "); userinput = Character.toUpperCase(input.next().charAt(0)); input.nextLine(); System.out.println(); if (userinput == 'A') { System.out.print("Please input the name of the song: "); songName = input.nextLine(); System.out.print("Please input the name of the artist: "); artist = input.nextLine(); System.out.print("Please input the release date of the song: "); year = input.nextInt(); System.out.print("Please input the song length (in seconds): "); length = input.nextInt(); input.nextLine(); System.out.print("Please input the song lyrics (lowercase, exclude punctuation): "); lyrics = input.nextLine(); Song tempSong = new Song(songName, artist, year, length, lyrics); songList.put(tempSong); String[] words = lyrics.split(" "); for (int i = 0; i < words.length; i++) { if (words[i] != "i" || words[i] != "im" || words[i] != "that" || words[i] != "and" || words[i] != "you" || words[i] != "is" || words[i] != "it" || words[i] != "its" || words[i] != "but" || words[i] != "who" || words[i] != "whos" || words[i] != "so" || words[i] != "with" || words[i] != "me" || words[i] != "in" || words[i] != "on" || words[i] != "a" || words[i] != "go" || words[i] != "to" || words[i] != "how" || words[i] != "all" || words[i] != "like" || words[i] != "up" || words[i] != "got") { if (!wordList.contains(new WordID(words[i], false))) { WordID newWord = new WordID(words[i], true); wordList.put(newWord); } id = wordList.get(new WordID(words[i], false)).getID(); while (searchList.size() <= id) { searchList.add(new BST()); } if (searchList.get(id).search(tempSong, false, new NameComparator()) == null) { searchList.get(id).insert(tempSong, new NameComparator()); } } } } else if (userinput == 'B') { if (songList.getNumElements() == 0) { System.out.println("No Songs to Display"); } else { System.out.println(songList.toString()); System.out.print("Enter the name of the song you would like to remove: "); songName = input.nextLine(); System.out.print("Enter the name of the song's artist: "); artist = input.nextLine(); Song tempSong = new Song(songName, artist); if (songList.contains(tempSong)) { lyrics = songList.get(tempSong).getLyrics(); String[] words = lyrics.split(" "); for (int i = 0; i < words.length; i++) { WordID tempWord = new WordID(words[i], false); if (wordList.contains(tempWord)) { id = wordList.get(tempWord).getID(); if (searchList.get(id).search(tempSong, false, new NameComparator()) != null) { searchList.get(id).remove(tempSong, new NameComparator()); } } } songList.remove(tempSong); } } } else if (userinput == 'C') { if (songList.getNumElements() == 0) { System.out.println("No Songs to Display"); } else { System.out.println("How would you like to search for a song? "); System.out.println("1. By name and artist"); System.out.println("2. By keyword"); System.out.print(" Enter your choice: "); userinput = input.next().charAt(0); input.nextLine(); if (userinput == '1') { System.out.print(" Enter the name of the song you would like to search: "); songName = input.nextLine(); System.out.print("Enter the name of the song's artist: "); artist = input.nextLine(); Song tempSong = new Song(songName, artist); System.out.println(); if (songList.contains(tempSong)) { System.out.println(songList.get(tempSong).getDetails()); } else { System.out.println("Song with name " + songName + " by " + artist + " not found."); } } if (userinput == '2') { System.out.print(" Enter the word you would like to search: "); String word = input.nextLine(); WordID tempWord = new WordID(word, false); if (wordList.contains(tempWord)) { id = wordList.get(tempWord).getID(); if (searchList.get(id).getSize() == 0) { System.out.println(" No songs containing " + word + " found."); } else { searchList.get(id).constructList(); List tempList = searchList.get(id).getList(); System.out.print(tempList.printNumberedList()); System.out.println(); System.out.print( "To view more information about any of these songs, enter the number next to the song title: "); int select = input.nextInt(); input.nextLine(); System.out.println(); if (select > tempList.getLength()) { System.out.println("Invalid option."); } else { tempList.placeIterator(); for (int i = 0; i + 1 < select; i++) { tempList.advanceIterator(); } System.out.println(tempList.getIterator().getDetails()); } } } else { System.out.println(" No songs containing " + word + " found."); } } } } else if (userinput == 'D') { if (songList.getNumElements() == 0) { System.out.println("No Songs to Display"); } else { System.out.println(songList.toString()); System.out.print("Enter the name of the song you would like to modify: "); songName = input.nextLine(); System.out.print("Enter the name of the song's artist: "); artist = input.nextLine(); Song searcher = new Song(songName, artist); if (songList.contains(searcher)) { System.out.println(" Select one of the options that you want to update: "); System.out.println("1. Song Name"); System.out.println("2. Artist Name"); System.out.println("3. Year Released"); System.out.println("4. Length"); System.out.println("5. Lyrics"); System.out.print(" Enter your choice: "); userinput = input.next().charAt(0); input.nextLine(); Song tempSong = songList.get(searcher); if (userinput == '1') { System.out.print("Enter updated name of the song"); songName = input.nextLine(); tempSong.setName(songName); songList.remove(tempSong); songList.put(tempSong); System.out.println(songList.toString()); } else if (userinput == '2') { System.out.print("Enter new artist name"); artist = input.nextLine(); tempSong.setArtist(artist); songList.remove(tempSong); songList.put(tempSong); System.out.println(songList.toString()); } else if (userinput == '3') { System.out.print("Enter new year released"); year = input.nextInt(); input.nextLine(); tempSong.setYear(year); songList.remove(tempSong); songList.put(tempSong); System.out.println(songList.toString()); } else if (userinput == '4') { System.out.print("Enter new song length"); length = input.nextInt(); input.nextLine(); tempSong.setLength(length); songList.remove(tempSong); songList.put(tempSong); System.out.println(songList.toString()); } else if (userinput == '5') { lyrics = tempSong.getLyrics(); String[] words = lyrics.split(" "); for (int i = 0; i < words.length; i++) { WordID tempWord = new WordID(words[i], false); if (wordList.contains(tempWord)) { id = wordList.get(tempWord).getID(); if (searchList.get(id).search(tempSong, false, new NameComparator()) != null) { searchList.get(id).remove(tempSong, new NameComparator()); } } } System.out.print("Enter new lyrics: "); lyrics = input.nextLine(); tempSong.setLyrics(lyrics); songList.remove(tempSong); songList.put(tempSong); words = lyrics.split(" "); for (int i = 0; i < words.length; i++) { if (words[i] != "i" || words[i] != "im" || words[i] != "that" || words[i] != "and" || words[i] != "you" || words[i] != "is" || words[i] != "it" || words[i] != "its" || words[i] != "but" || words[i] != "who" || words[i] != "whos" || words[i] != "so" || words[i] != "with" || words[i] != "me" || words[i] != "in" || words[i] != "on" || words[i] != "a" || words[i] != "go" || words[i] != "to" || words[i] != "how" || words[i] != "all" || words[i] != "like" || words[i] != "up" || words[i] != "got") { if (!wordList.contains(new WordID(words[i], false))) { WordID newWord = new WordID(words[i], true); wordList.put(newWord); } id = wordList.get(new WordID(words[i], false)).getID(); while (searchList.size() <= id) { searchList.add(new BST()); } if (searchList.get(id).search(tempSong, false, new NameComparator()) == null) { searchList.get(id).insert(tempSong, new NameComparator()); } } } } } else { System.out.println(" Song with name " + songName + " by " + artist + " not found."); } } } else if (userinput == 'E') { System.out.println("Total songs: " + songList.getNumElements()); double totalWords = 0; double totalLength = 0; ArrayList> tempTable = songList.getTable(); for (int i = 0; i < tempTable.size(); i++) { List tempList = tempTable.get(i); if (!tempList.isEmpty()) { tempList.placeIterator(); for (int j = 0; j < tempList.getLength(); j++) { totalWords += tempList.getIterator().getWordCount(); totalLength += tempList.getIterator().getLength(); tempList.advanceIterator(); } } } System.out.println( "Average song length: " + df.format(totalLength / songList.getNumElements()) + " seconds"); System.out.println( "Average wordcount per song: " + df.format(totalWords / songList.getNumElements()) + " words"); } else if (userinput == 'X') { System.out.print("Please input a file name to write songs to: "); String fileName = input.nextLine(); File outFile = new File(fileName); PrintWriter out = new PrintWriter(outFile); String output = ""; ArrayList> tempTable = songList.getTable(); for (int i = 0; i < tempTable.size(); i++) { List tempList = tempTable.get(i); if (!tempList.isEmpty()) { tempList.placeIterator(); for (int j = 0; j < tempList.getLength(); j++) { output += tempList.getIterator().toFile(); tempList.advanceIterator(); } } } out.print(output); out.close(); System.out.println(" Goodbye!"); } else { System.out.println("Invalid menu option. Please enter A-E or X to exit. "); } } input.close(); } catch (FileNotFoundException e) { System.out.println("Unable to open file."); } } } 

Song.input.txt

My Boo

Usher

2004

223

theres always that one person that will always have your heart you never see it coming cause youre blinded from the start know that youre that one for me its clear for everyone to see oh baby ooh yeah uh uh uh you gotta rockaway to this one cmon you will always be my boo see i dont know bout yall but i know about us and uh its the only way we know how to rock i dont know bout yall but i know about us and uh its the only way we know how to rock do you remember girl i was the one who gave you your first kiss cause i remember girl i was the one who said put your lips like this even before all the fame and people screaming your name girl i was there when you were my baby it started when we were younger you were mine my boo now another brothers taken over but its still in your eyes my boo even though we used to argue its alright my boo i know we havent seen each other in a while but you will always be my boo i was in love with you when we were younger you were mine my boo and i see it from time to time i still feel like my boo and i can see it no matter how i try to hide my boo and even though theres another man whos in my life you will always be my boo yes i remember boy cause after we kissed i could only think about your lips yes i remember boy the moment i knew you were the one i could spend my life with even before all the fame and people screaming your name i was there and you were my baby it started when we were younger you were mine my boo now another brothers taken over but its still in your eyes my boo even though we used to argue its alright my boo i know we havent seen each other in a while but you will always be my boo i was in love with you when we were younger you were mine my boo and i see it from time to time i still feel like my boo and i can see it no matter how i try to hide my boo and even though theres another man whos in my life you will always be my oh my oh my oh my oh my my boo my oh my oh my oh my oh my boo it started when we were younger you were mine my boo now another brothers taken over but its still in your eyes my boo even though we used to argue its alright my boo i know we havent seen each other in a while but you will always be my boo i dont know about yall but i know about us and uh its the only way we know how to rock i dont know about yall but i know about us and uh its the only way we know how to rock it started when we were younger my boo

Cry Me A River

Justin Timberlake

2002

288

you were my sun you were my earth but you didnt know all the ways i loved you no so you took a chance made other plans but i bet you didnt think that they would come crashing down no you dont have to say what you did i already know i found out from him now theres just no chance with you and me therell never be dont it make you sad about it you told me you love me why did you leave me all alone now you tell me you need me when you call me on the phone girl i refuse you must have me confused with some other guy the bridges were burned now its your turn to cry cry me a river cry me a river cry me a river cry me a river you know that they say that somethings are better left unsaid it wasnt like you only talked to him and you know it dont act like you dont know it all of these things people told me keep messing with my head shouldve picked honesty then you may not have blown it you dont have to say what you did i already know i found out from him now theres just no chance with you and me therell never be dont it make you sad about it you told me you love me why did you leave me all alone now you tell me you need me when you call me on the phone girl i refuse you must have me confused with some other guy the bridges were burned now its your turn to cry cry me a river go on and just cry me a river go on and just cry me a river baby go on and just cry me a river oh the damage is done so i guess i be leaving oh the damage is done so i guess i be leaving oh the damage is done so i guess i be leaving oh the damage is done so i guess i be leaving you dont have to say what you did i already know i found out from him now theres just no chance with you and me therell never be dont it make you sad about it cry me a river go on and just cry me a river baby go on and just cry me a river you can go on and just cry me a river cry me a river baby go on and just cry me a river go on and just cry me a river oh baby cry cry me a river i dont wanna cry no more cry me a river cry me a river cry me a river cry me a river cry me a river cry me cry me cry me a river cry me cry me cry me a river cry me cry me cry me a river cry me cry me cry me a river cry me cry me cry me a river cry me cry me cry me a river cry me cry me

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 Programming Questions!