Introduction to Programming

Part 1: This lab will continue to work with the data file SciFiDataBMTErr2.txt . We are going to modify the program you wrote for Lab3Part3. Create a new application Lab4Part1 and copy your code from Lab3Part3 into this new program. In your new program, we are now going to create arrays to save all of the data from the input file. We are going to use some single dimension arrays and some multi-dimensional arrays for this. 1.a) In Lab3 Part3 you stored the title, series number, series name, and price into single-dimensional arrays. For Lab4Part1, you will create the following arrays to store the data: • Declare a 2-dimensional String array of 3 columns and 75 rows that will hold the title, series name, and content type. Call this array names. {3 pts} • Declare a 2-dimensional int array of 3 columns and 75 rows that will hold the book year, movie year, and TV year data. Call this array years. {3 pts} • Use the 1-dimensional double array for book prices from Lab3Part3. Increase the size to 75 rows. {1 pts} • Declare an ArrayList of size 75 of String class to hold the BookCover Type. Call this bookCoverType {2 pts} • Declare an ArrayList of size 75 of Integer class to hold the Series Number. Call this array seriesNum {2 pts} • A 1-dimensional array of Strings of size 8 that will temporarily hold the data on Books, Movies and TV from each line of the file. {1 pts} 1.a) will be graded in the Lab4Part1 . {12 points total} 1.b) You are also going to read in the data from the file in a different way than you did in the Lab3Part3. For Lab4Part1 you are going to read in the Content Type, Title, Series Number and Series Name as you did previously. You will store these into the names array and the seriesNum ArrayList. All the strings should be stored in the same row of the names array. The three names go in the three columns of that array. The Series Number goes in the seriesNum array. 1.b) will be graded in the Lab4Part1 . {11 points; 3 per string, 2 per number} 1.c) After the colon, read the remainder of line of data in the file into a single string, called strBMT, using the .nextLine method. Using strBMT, split the data into separate words, determine which media info is there, convert the values to numbers as needed and store the data into the appropriate arrays. The year values go into the years array in the appropriate column, the book cover into its array bookCoverType and the price in its array. In the years array, the first column [0] is the column for the Book year, the column [1] is for the Movie year, and the column [2] is for the TV year. Be sure to store the year data in the correct column. 1.c) will be graded in the Lab4Part1 . {12 points; 3 per year, 1 for price, 2 for cover type} 1.d) Write a method that will print out a table that displays the following data. The method should take in the names, years, and seriesNum arrays as input parameters. Use the method to print a table with a title row and then data in each row as follows. See the example below for the format you need to create for the table. Title SeriesNum Book Movie TV Dr. Who 4 1964 1966 1963 The Princess Bride 27 1973 1987 Episode II Attack of the Clones 16 2002 Hogfather 2 1996 The Phantom Tollbooth 26 1961 2019 Voyager 13 1995 Soul Music 2 1994 1997 Episode V Empire Strikes Back 20 1980 Episode I The Phantom Menace 15 1999 1999 Discovery 10 2017 The Prisoner of Azkaban 6 1999 2004 Spock Must Die 8 1970 Run Lab4Part1 and take a screenshot of the output table. Include the output table screenshot in the answers document. {12 points total; table format 6pts; table content 6pts} 1.e) Write a method called searchArray that searches the names array to try to find a title that the user enters. Pass the names array into the method. In the method, let the user enter a string to search for. If it is found in the array, return the index of where of title is in the array. If it is not found, give a message. Run Lab4Part1 and take a screenshot of the output . Include the output screenshot in the answers document. {10 points total; method decl 2 pts; search alg 6 pts; result 2 pts} 1.f) Copy the titles from the names array into an array of titles only. Then write a method called sortArray that sorts the titles array. Pass the titles array into the method. Print the unsorted titles array. Then sort the titles array using a bubble sort algorithm that you write. After the array is sorted, print the sorted array. Run Lab4Part1 and take a screenshot of the output . Include the output screenshot in the answers document {13 points total; method decl 2 pts; print 2 pts; bubble sort 9 pts} Save Lab4Part1 (through part 1.f) in your Lab4 folder to submit. 2) Create a new application Lab4Part2 . In this application you are going to let the user choose to do various conversions. You will set the program up to have a simple text based menu, you will let the user choose which type of conversion to do, and after the conversion have a loop that will let them choose to do another conversion if desired. Your menu should have the following choices: Choose one of the following: 1) Convert a decimal value to a boolean 2) Convert a boolean value to a decimal 3) Convert a decimal value to a hexadecimal 4) Convert a hexadecimal value to a decimal 5) Convert a boolean value to a hexadecimal 6) Convert a hexadecimal value to a boolean Ask the user to enter their choice and then have the user enter a value of the first type. Call a method to convert the input value to the new base and print the result. You can write 6 separate methods or you can write methods that call each other. Allow the user to choose a new menu conversion option until they are ready to end the program. Save Lab4Part2 in your Lab4 folder to submit. {15 points total} {menu and user choice 3 pts} {dec to boolean 2 pts} {boolean to dec 2 pts} {dec to hex 2 pts} {hex to dec 2 pts} {boolean to hex 2 pts} {hex to boolean 2 pts} 3) Create a new application Lab4Part3 and copy Lab4Part1 into the Lab4Part3. Declare an ArrayList called titlesAL to held Strings and then put all of the Strings from the titles array into the new ArrayList. Call the method searchSortAL at the end of the main method. Write a method searchSortAL that takes in the titlesAL ArrayList. In searchSortAL, print the input ArrayList and then ask the user if they wish to sort the array or search the array. Once the user chooses, then use the ArrayList methods to sort or search. If the user wants to sort the array, use the Collections.sort to sort it and print the resulting ArrayList. If the user wants to search, get the user’s input to search for and then use the built-in methods to search the ArrayList and find the index of the value the user is looking for. If it is found in the ArrayList, return the index of where of title is. If it is not found, give a message. Save Lab4Part3 in your Lab4 folder to submit.            

Sample Solution