Exam 2 • Instructions • Question 1 • Question 2 • Submit! Instructions Important: Read all of these instructions before beginning this exam. • You have 120 minutes (two hours) to complete all the...

-


Exam 2 • Instructions • Question 1 • Question 2 • Submit! Instructions Important: Read all of these instructions before beginning this exam. • You have 120 minutes (two hours) to complete all the questions. This will be enforced using the exam timer on Vocareum. Failure to submit before the timer reaches 0 or by 6:00 pm Tuesday, November 2 (whichever comes first) will result in an exam score of 0. • Submitting your work on Vocareum will save your progress and record a snapshot of your current solution. The most recent submission will be the one that is graded. Vocareum is configured to automatically submit your work folder when the timer expires, but you should not rely on this. It is highly recommended to submit frequently. There is no limit on the number of times you can submit on Vocareum. Failure to submit will result in an exam score of 0. • This exam consists of 2 free-response coding questions: o Question 1 is worth 50 points. o Question 2 is worth 50 points. • This exam is open book, open notes. You may also reference lecture slides, lecture videos, and previous Campuswire posts. You may not utilize any other electronic sources. • All work must be your own. Accepting assistance from another student or outside individual, or copying code from any source (other than code you have written yourself) is cheating and is strictly prohibited. • You may choose to do your work in either a local IDE (Intellij, Eclipse, etc.) or on Vocareum. Regardless of your choice, you must submit your solutions via Vocareum before the timer reaches 0 or by 6:00 pm Tuesday, November 2 (whichever comes first). • You may not post questions regarding the exam anywhere, including Campuswire and any other online forums, websites, or communication channels. • Your submission must compile on Vocareum to be graded. If your submission has compilation errors and does not compile, you will receive a zero for that question. https://labs.vocareum.com/web/1590270/590619.1/ASNLIB/public/docs/README.html#1 https://labs.vocareum.com/web/1590270/590619.1/ASNLIB/public/docs/README.html#2 https://labs.vocareum.com/web/1590270/590619.1/ASNLIB/public/docs/README.html#3 https://labs.vocareum.com/web/1590270/590619.1/ASNLIB/public/docs/README.html#4 • You will not receive any partial credit if your submission has compilation errors. • If you run into any technical or access problems, you must immediately email [email protected]. Question 1 – CourseCatalog A local college has asked you to implement a course catalog tracker. This tool will be helpful for anyone wishing to track courses by their course number, instructor, time, and location. The organization already has a file with all the courses available, but it is not formatted in a way that is easy to read. Your tool will reformat the file into a more comprehensible format. This question will require that you process an input file and generate an output file. The input file will include a list of entries which a set of courses. The output file will include this information formatted in a more readable fashion. You must create and implement one class: CourseCatalog. All CourseCatalog methods must be public and static. Note: • In this question, we ask you to implement a variety of methods. You should not assume that the methods will be called in any particular order. That is, we may call a method directly rather than running your program with the main method. Implement processing accordingly. • As we have noted in all your other assignments that process user input, do not use multiple Scanners, static Scanners, or global Scanners during this question. You will not receive any credit for a solution that does so. • Use caution for any static field. Remember that it will be shared by the class, so any values assigned statically will appear in every test case. If your program depends on a static field for processing, it will likely fail most of the tests. You should not add any field or method other than what we describe in the requirements. • Your code must compile to be scored. Otherwise, you will lose all the points for this question. Implementation Guidelines mailto:[email protected] File Format You must read data from files to answer this question. Typically, the file will have the following format: COURSE_NUMBER;INSTRUCTOR;START_TIME;END_TIME;LOCATION COURSE_NUMBER;INSTRUCTOR;START_TIME;END_TIME;LOCATION COURSE_NUMBER;INSTRUCTOR;START_TIME;END_TIME;LOCATION COURSE_NUMBER;INSTRUCTOR;START_TIME;END_TIME;LOCATION Where each of the items is replaced by their respective values. For example, a file may contain the following: PHYS59740;Mike Smith;01700;01800;STEW SPAN25240;Jane Doe;01900;02000;STEW HIST34020;Danny Evans;01900;02000;LWSN Each line will contain five items: The course number, the instructor name, the start time, the end time, and the location. You may assume that all input files have separate values with a single semicolon, “;". Each course will be on a single line. CourseCatalog Methods Method Name Return Type Access Modifier Parameters main void public static String[] args readFile String[] public static String filename writeFile void public static String[] courses, String filename Note: All methods must be public and static. Method Descriptions Method Description main Using a Scanner declared and instantiated within the main method, prompt the user to enter the input file name. If the file is read successfully, prompt the user to enter an output file name. Print success messages or errors as appropriate. The expected flow of control is included below. Sample output is included in the next section. 1. Declare and instantiate a Scanner (You must do this within the main method) 2. Prompt the user to enter the input file name. 3. Read the input file by calling the readFile method. a. If there is an error while reading the input file, print the input file error message. b. If the file is read successfully, prompt the user to enter the output file name. i. If there is an error while writing to the output file, print the output file error message and end the program. ii. If the file is written successfully, print the success prompt and end the program. Note: If your Scanner is declared or instantiated outside the main method, you will not receive credit for this question. readFile Read the contents of the file specified by the parameter. Record each line in the String array. If the file is read successfully, you may simply return the array. If any exception occurs, throw it to the main method for handling. writeFile Using the parameters, write the contents of the array to the specified file. The array content should be written in order, that is, the first element in the array will be the first line in the file, and so on. Format each of the lines before writing by following the example below. For an input line with contents as follows: PHYS59740;Mike Smith;01700;01800;STEW The corresponding formatted output line would be "The course PHYS59740 is taught by Mike Smith which runs from 01700 until 01800 in building STEW" If the file is written to successfully, simply return. If any exception occurs, throw it to the main method for handling. Output You are not required to print any output to the console for this question. The tests will check if your methods return the proper values, read the correct files, and write the correct content to the output files. We provide the output prompts in the example (such as, “What is the name of the file you want to read from?”), but you may choose to omit them from your solution if you like. As long as your methods function as described, accepting input from the command line in the correct order, reading and writing to files as expected, you will receive full credit even if you omit the prompts. We provide all the prompts in the Starter Code. The user will enter the inputs as documented in the main method description. You must handle them appropriately. Test Run – Success [No prompts] Note: Brackets [] indicate input. [input.txt] [output.txt] Input.txt Contents PHYS59740;Mike Smith;01700;01800;STEW SPAN25240;Jane Doe;01900;02000;STEW HIST34020;Danny Evans;01900;02000;LWSN Output.txt Contents The course PHYS59740 is taught by Mike Smith which runs from 01700 until 01800 in building STEW The course SPAN25240 is taught by Jane Doe which runs from 01900 until 02000 in building STEW The course HIST34020 is taught by Danny Evans which runs from 01900 until 02000 in building LWSN Test Run – Success [Including Prompts] What is the name of the file you want to read from? [input.txt] The given filename was processed! What is the file that you want to output data to? [output.txt] Writing to a new file since it doesn't already exist! Writing to the file was successful! Input.txt Contents SPAN11350;Charles Doe;1000;01100;CL50 CS36940;John Smith;02100;02200;WALC Output.txt Contents The course SPAN11350 is taught by Charles Doe which runs from 1000 until 01100 in building CL50 The course CS36940 is taught by John Smith which runs from 02100 until 02200 in building WALC Test Run – Read Error [Including Prompts] Note: Brackets [] indicate input. What is the name of the file you want to read from? [input.txt] The given filename was not in the right format! Input.txt Contents PHYS59740; 1234 Note: Notice that both of the lines in this file are not formatted properly. We include an error message in the starter code, but you will be evaluated on whether or not your program handles these types of errors without crashing and without behaving in an unspecified manner. Test Run – Write Error [Including Prompts] Note: Brackets [] indicate input. What is the name of the file you want to read from? [input.txt] The given filename was processed! What is the file that you want to output data to? [output.txt] There was an error when writing to the file! Input.txt Contents SPAN25240;Jane Doe;01900;02000;STEW HIST34020;Danny Evans;01900;02000;LWSN
Nov 02, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here