1.) Using the attached SCISCourses.txt file, create a program that begins by loading the file onto an arraylist of College Courses called Catalog.

Published on December 2017 | Categories: Government & Politics | Downloads: 52 | Comments: 0 | Views: 369
of 1
Download PDF   Embed   Report

Each College Course class consists of 3 attributes: course name,number of credits, and course title. 1a.) Include exception handling for: FileNotFoundException, BadDataException, IOException Throw your own exception class, BadDataException, when you detect that: the credit hours in the file is not an int 1b.) The input file's records look like this: TCN 6880 3 Telecommunications Public Policy Development and Standards "TCN 6880" are considered the course name, 3 is the number of credits, and "Telecommunications Public Policy Development and Standards" is the course title. When reading in the file, you will have to concatenate the result of 2 .next() methods to create the course name as 1 field. Then, a .nextInt() should read the course credits, followed by a nextLine() to read the rest of the line to obtain the entire course title. 2.) Implement the Comparable interface for the College Course class, defining its own compareTo() method, based on the courseName . 3.) Sort the Catalog arraylist using Collections.sort(), and display the sorted Course file by course name. For each Course, display the course title and the number of credits. 4.) Add another sort of the Catalog arraylist, by course title. To implement this sort, you will need to implement a Comparator interface, and create a Comparator class. Save the results of this sort in a separate ArrayList from the one sorted by course title. Print a dividing line of asterisks, and then display all the Course by course title. 5.) Display a menu for the user to select from the following options, once the Courses arraylist is fully populated: 0. Input File, Print Contents Search by Course Name Search by Course Title Sort by CouseName, Print Sort by Course Title, Print Add a Course to the File Quit 6.) For the Catalog search, first sort the ArrayList of Courses by course name, using the Comparable interface and compareTo methods in the Courses class. Then, use the binary search method for Collections, Collections.binarySearch(), to find the course requested by the user. 7.) For the Course title search, sort the ArrayList of Courses by course title, using the Comparator interface and your comparator class. Once sorted by course title, use the binary search method for Collections, Collections.binarySearch() to find all the courses that for a particular prefix like "COP" or " CNT" requested by the user. Display the names of all the courses that have that prefix. 8.) Implement the Scanner and File classes to read the Course Catalog file. 9.) Implement the FileWriter and PrintWriter classes to write to the Course Catalog file. 10.) Catch exceptions such as IOException and FileNotFound. Thus, prompt the user for the name of the input/output file. Give the user a message that says "Enter SCISCourses2.txt for the file input." 11.) If the user selects the "add course to catalog" option, then prompt the user for all the information that makes up a Course object, and once created, add the new Course to the ArrayList of Courses. Don't forget to re-sort the ArrayList of Courses. Don't forget to permanently add the course to the external file, using the FileWriter and PrintWriter classes. It may be easier to create a .toString() method in the Course class, and then use it to write the new Course record to the file. (Ex.: outputStreamName.println(objectName) will invoke the .toString()) behind the scenes.)

Comments

Content

Each College Course class consists of 3 attributes: course name,number of credits, and course title. 1a.) Include exception handling for: FileNotFoundException, BadDataException, IOException Throw your own exception class, BadDataException, when you detect that: the credit hours in the file is not an int 1b.) The input file's records look like this: TCN 6880 3 Telecommunications Public Policy Development and Standards "TCN 6880" are considered the course name, 3 is the number of credits, and "Telecommunications Public Policy Development and Standards" is the course title. When reading in the file, you will have to concatenate the result of 2 .next() methods to create the course name as 1 field. Then, a .nextInt() should read the course credits, followed by a nextLine() to read the rest of the line to obtain the entire course title. 2.) Implement the Comparable interface for the College Course class, defining its own compareTo() method, based on the courseName . 3.) Sort the Catalog arraylist using Collections.sort(), and display the sorted Course file by course name. For each Course, display the course title and the number of credits. 4.) Add another sort of the Catalog arraylist, by course title. To implement this sort, you will need to implement a Comparator interface, and create a Comparator class. Save the results of this sort in a separate ArrayList from the one sorted by course title. Print a dividing line of asterisks, and then display all the Course by course title. 5.) Display a menu for the user to select from the following options, once the Courses arraylist is fully populated: 0. Input File, Print Contents Search by Course Name Search by Course Title Sort by CouseName, Print Sort by Course Title, Print Add a Course to the File Quit 6.) For the Catalog search, first sort the ArrayList of Courses by course name, using the Comparable interface and compareTo methods in the Courses class. Then, use the binary search method for Collections, Collections.binarySearch(), to find the course requested by the user. 7.) For the Course title search, sort the ArrayList of Courses by course title, using the Comparator interface and your comparator class. Once sorted by course title, use the binary search method for Collections, Collections.binarySearch() to find all the courses that for a particular prefix like "COP" or " CNT" requested by the user. Display the names of all the courses that have that prefix. 8.) Implement the Scanner and File classes to read the Course Catalog file. 9.) Implement the FileWriter and PrintWriter classes to write to the Course Catalog file. 10.) Catch exceptions such as IOException and FileNotFound. Thus, prompt the user for the name of the input/output file. Give the user a message that says "Enter SCISCourses2.txt for the file input." 11.) If the user selects the "add course to catalog" option, then prompt the user for all the information that makes up a Course object, and once created, add the new Course to the ArrayList of Courses. Don't forget to re-sort the ArrayList of Courses. Don't forget to permanently add the course to the external file, using the FileWriter and PrintWriter classes. It may be easier to create a .toString() method in the Course class, and then use it to write the new Course record to the file. (Ex.: outputStreamName.println(objectName) will invoke the .toString()) behind the scenes.)

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close