Question: 0.) Display a menu for the user to select from the following options, once the Courses arraylist is fully populated: 0. Input File, Print Contents
0.) Display a menu for the user to select from the following options, once the
Courses arraylist is fully populated:
0. Input File, Print Contents
1. Sort & Print by Course Name
2. Sort & Print by Course Title
3. Search by Course Name
4. Search by Course Title
5. Add Course to Catalog File
6. Quit
1.) When the user selects option 0, ask the user for the file name. Have the user enter
the attached SCISCourses.txt file, so the program will load the file onto an arraylist of
College Courses called Catalog. Use a try-catch block, so that if the name is invalid the
catch block with ask the user to enter the file name again. Once the file is valid,
proceed with reading it until the end of file. As each record in the file is read, create a
College Course object consisting of 3 attributes: course name, number of credits, and
course title. Add each College Course object to the arrayList of College Courses.
1a.) Include exception handling for:
FileNotFoundException, NumberFormatException, InputMismatchException,
IndexOutOfBoundsException, and BadDataException (customized exception class)
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.) Write a method that will sort the Catalog arraylist using Collections.sort(), and
display the sorted Course file by course name. Display all the Courses by course
name. This will use the Comparable interface to sort.
4.) Write another method that will 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. Display all the Courses by course title.
5.) For the search by course name, 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.
6.) For the search by course title, 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 with a particular course title
requested by the user. Use the comparator for the binary search method
also. Display the names of all the courses that have that course title.
7.) Implement the Scanner and File classes to read the Course Catalog file.
8.) Implement the FileWriter and PrintWriter classes to write to the Course
Catalog file, at the end of the file, keeping what was already there.
9.) Catch exceptions such as 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."
10.) 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, and permanently add the course
to the external file, using the FileWriter and PrintWriter classes. The user must re-sort
the ArrayList of Courses, in order for subsequent searches to work properly.
11.) Create a new class, BadDataException - when credit hours entered are greater than 5
Throw BadDataException, when user is adding a new record to file, and the user
enters credit hours > 5
Catch the BadDataException by notifying user of hours' limitation, and asking user
to re-enter data
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
