Instructor The Instructor class implements the Serializable interface so that its object can be stored as one piece. (The Serializable interface is defined in the java.io package.) Note: The...



Instructor


TheInstructorclass implements the
Serializable
interface so that its object can be stored as one piece. (TheSerializableinterface is defined in thejava.iopackage.) Note: The Serializable interface contains no abstract methods or constants, the keyword
Serializable
simply signal the program that the object can be serialized.



Course


TheCourseclass implements the
Serializable
interface so that its object can be stored as one piece. (TheSerializableinterface is defined in thejava.iopackage.) Note: The Serializable interface contains no abstract methods or constants, the keyword Serializable simply signal the program that the object can be serialized.


The relationship between classCourseandInstructoris aggregation,i.e.everyCourseobject has an Instructor as part of its instance variables (see above UML diagram).



CourseNameComparator


TheCourseNameComparatorclass implements the
Comparator
interface (the Comparator interface is injava.utilpackage.). It needs to override the following abstract method:


public int compare(Object first, Object second)


Note if you use generics to define it (recommended), it should be:


public int compare(Course first, Course second)


If the first argumentCoursehas its name less than that of the second argument, an integer less than zero is returned. If the first argumentCoursehas its name larger than that of the second argument, an integer greater than zero is returned. If the twoCoursenames are the same, then 0 should be returned. The way we compare the two Course's name are similar to how we compare two strings, so you should use the
compareTo
method of the
String
class.


Basically, if we use thisCourseNameComparator,courses should be listed in the alphabetical order of their names!



CourseInstructorComparator


TheCourseInstructorComparatorclass implements theComparatorinterface (the Comparator interface is injava.utilpackage.). It needs to override the following abstract method:


public int compare(Object first, Object second)


Or similar as above, if you use generics, it can be defined as:


public int compare(Course first, Course second)


For the course's current instructor, we will compare their last name,i.e.,if the first argument object has itsinstructorless than that of the second argument, an integer less than zero is returned; if the first argument object has itsinstructor's last name larger than that of the second argument, an int greater than zero is returned.


Basically, if we use thisCourseInstructorComparator,the course'scurrentInstructorshould be listed in the alphabetical order of their names!



Sorts


TheSortsclass is a utility class that will be used to sort a list ofCourseobjects base on different criteria, such as the course's name & university or instructor. Sorting algorithms are described in the algorithm note posted on our course web site. You can use any sorting algorithms, such as Selection sort, Insertion Sort, MergeSort, or QuickSort, but make sure your sort method should be able to sort an ArrayList of objects. The
Sorts
class will never be instantiated and it should only contain the followingstaticmethod:


public static void sort(ArrayList courseList, Comparator xComparator)


ThexCompartorcan be an object of
CourseNameComparator or CourseInstructorComparator
which we defined above.i.e.we separate the algorithm from its underlying data structure, this is one of the key concepts of generic programming! Your sort method utilizes the compare method of the parameterComparatorobject to sort. As we mentioned above, you can use any sorting algorithms which you feel comfortaable with, but the sort method's header must be above.



CourseManagement


TheCourseManagementclass has a list of Course objects that can be organized by the Course management system. The Course management system will be a fully encapsulated object. TheCourseManagementclass implements theSerializableinterface so that its object can be stored as one piece. It has the following attributes:

















Attribute name




Attribute type




Description



courseList



an ArrayList ofCourseobjects



A list of Course objects in the Course management system



The following public methods should be provided to interact with the Course management system:















































Method




Descipriton



CourseManagement( )



A Constructor of the CourseManagement class. It will create and instantiate thecourseList.



int courseExists(String courseName, String universityName)



Search for a Course object incourseListby both its name and university and return the index of the object if it is found; otherwise return -1. Note: same Course can exist indifferent universities,i.e.,it's possible that two courses have the same name, but with different universities.



int instructorExists(String firstName, String lastName, String officeNum)



Search for aninstructorin Course objects in thecourseListthat has the samefirstName, lastNameandofficeNuminfo. and return the index of such object if it is found, otherwise return -1.



boolean addCourse(String courseName, String university, String firstName, String lastName, String officeNum)



Add a Course object to thecourseListand returntrueif such an object is added successfully; otherwise returnfalse.Two Courses are considered duplicated if they have exactly the same course name and university name. Note: duplicated Course shall NOT be added inside the courseList.



boolean removeCourse(String courseName, String university)



Remove a Course object with the given course name and university name from thecourseList, and returntrueif the Course object is removed successfully; otherwise returnfalseif the Course does not exist.



void sortByCourseName()



Sort thecourseListby course names in alphabetical order. This method calls thesortmethod in theSortsclass by using an object generated fromtheCourseNameComparatorclass.



void sortByCourseInstructor()



Sort thecourseListby Courses'
instructor
in the alphabetical order of their last names. This method calls thesortmethod defined in theSortsclass by using an object generated from theCourseInstructorComparatorclass.



String listCourses()



List all Course objects incourseList. The returned string is the concatenation of each Course object information.Hint: you can utilize CourseclasstoStringmethod to complete this method, and add "\n"at the beginning and at the end of the result string. If there is no Course in the courseList, this method should return the string containing "\nNo Course\n\n".



void closeCourseManagement()



Close the Course management system by making thecourseListempty. This can be done by removing each Course object fromcourseList.






No input/output should occur in the Course management system.User interaction should be handled only by the driver class (Assignment8.javaclass).



Assignment8


All input and output should be handled in Assignment8 class. The main method should start by displaying this updated menu in this exact format:


Choice\t\tAction\n
------\t\t------\n
A\t\tAdd a course\n
C\t\tCreate a CourseManagement\n
D\t\tSearch a course\n
E\t\tSearch an instructor\n
L\t\tList courses\n
N\t\tSort by course names\n
P\t\tSort by current instructor name\n
Q\t\tQuit\n
R\t\tRemove a course\n
T\t\tClose CourseManagement\n
U\t\tWrite strings to a text file\n
V\t\tRead strings from a text file\n
W\t\tSerialize CourseManagement to a data file\n
X\t\tDeserialize CourseManagement from a data file\n
?\t\tDisplay Help\n


What action would you like to perform?\n


Read in the user input and execute the appropriate command. After the execution of each command, redisplay the prompt. Commands should be accepted in both lowercase and uppercase.



Option A: Add a Course


This part asks user for a course's name, university name, and instructor (first name, last name, office number), it then create aCourseobject and add it inside thecourseList. If the Course is added successfully, it will print the following message:


System.out.print("Course added\n");


Otherwise,


System.out.print("Course NOT added\n");



Option C: Create a new CourseManagement


This part is already implemented in Assignment8.java file.

Option D: Search a Course


This part searchescourseListby a specific course's name AND the university.


If the course exists, print for example:


Electrical Engineering at Arizona State University is found


If the course does not exist, then print for example:


Mechanical Engineering at Arizona State University is NOT found



Option E: Search an Instructor


This part searchescourseListby a specific instructor's first name, last name and office number. If there exists one Course object in courseList that has such an instructor, the program prints, for example:


Instructor: John Smith, Assistant Professor is found


The format of the print out will be:



"Instructor: " + firstName + " " + lastName + ", " + officeNum + " is found\n"


If the specific instructor does not exist, then print for example:


Instructor: Mary Johnson, Assistant Professor is NOT found



Option L: List courses


Each Course object incourseListshould be displayed by using thetoStringmethod provided in theCourseclass. (and usinglistCourses() method in theCourseManagementclass). Add "\n" at the beginning and "\n" at the end of the result string. If there is no Course in thecourseList, the methodlistCourses() should return the string containing"\nNo Course\n\n" (thereby the final output is "\n\nNo Course\n\n\n")



Option N: Sort by Course Names


This part should sort all courses incourseListin the alphabetical order of their courses' names. You should usesortByCourseName() method inCourseManagementclass to achieve this.



Option P: Sort by Instructor Names


This part should sort all courses incourseListin the alphabetical order of their instructors' names. You should usesortByCourseInstructor() method inCourseManagementclass to achieve this.



Option Q: Quit


This option will terminate the program.



Option R: Remove a Course


Given a Course's name and its university info., this option removes the specific course fromcourseListif it exists, print for example


Electrical Engineering at Arizona State University is removed


The format of the print out will be:


courseName + " at " + university + " is removed\n"


If the Course does not exist, then print:


courseName + " at " + university + " is NOT removed\n"



Option T: Close CourseManagement


This part is given in Assignment8.java. It deletes all Course objects. Then, display the following:


Course management system closed\n



Option U: Write strings to a text file


Your program should display the following prompt:


Please enter a file name that we will write to:\n


Read in the filename and create an appropriate object to get ready to read from the file. Then it should display the following prompts:


Please enter a string to write inside the file:\n


Read in the string that the user entered, then attach "\n" at the end to the string and write it to the file. If the operation is successful, display the following:


FILENAME is written\n


ReplaceFILENAMEwith the actual name of the file.


Make sure to usetryandcatchto catch exceptions, such asIOException, etc, if something went wrong with the string writing, display the following message on screen.


Write string inside the file error\n



Option V: Read strings from a text file


Your program should display the following prompt:


Please enter a file name which we will read from:\n


Read in the file name and create an appropriate object to get ready to read from the file. If the operation is successful, display the following (replaceFILENAMEwith the actual name of the file):


FILENAME was read\n


Then read only the first line in the file, and display:


The first line of the file is:\n


CONTENT\n


whereCONTENTshould be replaced by the actual first line inside the file. A real example is as follows:


The first line of the file is:


ASU CSE205 Fall 2021 Assignment #8


Your program should catch both
FileNotFoundException
and
IOException
. If the file name cannot be found, display:


FILENAME was not found\n


where FILENAME is replaced by the actual file name. For all other reading errors, display:


Read string from the file error\n



Option W: Serialize CourseManagement to a data file


Your program should display the following prompt:


Please enter a file name to write:\n


Read in the filename and write the serializedCourseManagementobject (the variable
courseManagewr)
into it. Note that any objects to be stored must implementSerializableinterface. The Serializable interface is defined in java.io.* package. Your program should catch both
NotSerializableExeption
and
IOException
, and display the following error message on screen accordingly.


Not serializable exception\n


Data file written exception\n



Option X: Deserialize CourseManagement from a data file


Your program should display the following prompt:


Please enter a file name which we will read from:\n


Read in the file name and attempt to load the
CourseManagement
object from that file. Note: there is only one CourseManagement object (the variable
courseManager
) in the Assignment8 class, and the first object read from the file should be assigned to this CourseManagement object. If the operation is successful, display the following (replace FILENAME with the actual name of the file):


FILENAME was read\n


Your program should catch
ClassNotFoundException, NotSerializableExeption
and
IOException
, and display the following error message on screen accordingly.


Class not found exception\n
Not serializable exception\n
Data file read exception\n

Oct 30, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here