Question: please solve this it is data structure Lab Exercise: Implement the following classes: 1. class Course that includes four instance variables: private int ID; //
please solve this it is data structure






Lab Exercise: Implement the following classes: 1. class Course that includes four instance variables: private int ID; // course ID private String Name; // course name private Course next; // link next private Course prev; // link previous Your class should have the following: A constructor that initializes the two instance variables id and name Set and get methods for each instance variable. 2. class Department that includes three instance variables: private String deptName; private Course head, tail; Your class should have the following: a constructor that initializes the department name public boolean exist(int id) that checks whether the course object with id passed as parameter exists in the list or not. public boolean insert(int id, String n) that creates and adds the course if the course with id passed as parameter does not exist in the list. The course must be added in ascending order. The method will return false if the id was a duplicate. public boolean remove (int id) that deletes a course if it exists in the list and return true. The method will return false if the id was not found in the list. public String findCourse (int id) that returns a course name if the id exists in the list. public void print() that prints the department name and all the courses in the linked list in ascending order. public void printReverse() that prints the department name and all the courses in the linked list in descending order. Write the expected time and space complexity as a comment at the beginning of each method of your class. 3. Write a test application named Lab3test. In the main method, do the following: Input the department name then create a department object. Display a menu to the user and asking for a choice to be entered. As follows: The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: The program will perform the action selected by the user and display a proper message when necessary. The program will repeat these actions until the user terminates the program (Hint: Use a loop). Sample Output Please enter the name of the department: Computer Engineering The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 30 Error! Incorrect choice. The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 4 Computer Engineering department does not have any courses. The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 1 Enter the course number or -1 to stop: 300 Enter the course name: Design and Analysis of Algorithms Enter the course number or -1 to stop: 356 Enter the course name: Computer Networks I Enter the course number or -1 to stop: 300 Enter the course name: testing duplicate Error! duplicate ID number... Enter the course number or -1 to stop: 325 Enter the course name: Human-Computer Interaction Enter the course number or -1 to stop: 262 Enter the course name: Fundamentals of Digital Logic Enter the course number or -1 to stop: -1 The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses Enter the course name: Human-Computer Interaction Enter the course number or -1 to stop: 262 Enter the course name: Fundamentals of Digital Logic Enter the course number or -1 to stop: -1 The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 19 6- exit Please enter your selection: 4 Courses in Computer Engineering department are: 1 - 262 Fundamentals of Digital Logic 2 - 300 Design and Analysis of Algorithms 3 - 325 Human-Computer Interaction 4 - 356 Computer Networks I The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 5 Courses in Computer Engineering department printed in reverse are: 1 - 356 Computer Networks I 2 - 325 Human-Computer Interaction 3 - 300 Design and Analysis of Algorithms 4 - 262 Fundamentals of Digital Logic The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse Please enter your selection: 2 Enter the course number: 325 The course was removed The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 2 Enter the course number: 325 The course is not in the list The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit 20 Please enter your selection: 4 Courses in Computer Engineering department are: 1 - 262 Fundamentals of Digital Logic 2 - 300 Design and Analysis of Algorithms 3 - 356 Computer Networks I The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 5 Courses in Computer Engineering department printed in reverse are: Please enter your selection: 4 Courses in Computer Engineering department are: 1 - 262 Fundamentals of Digital Logic 2 - 300 Design and Analysis of Algorithms 3 - 356 Computer Networks I The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 5 Courses in Computer Engineering department printed in reverse are: 1 - 356 Computer Networks I 2 - 300 Design and Analysis of Algorithms 3 - 262 Fundamentals of Digital Logic The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 3 Enter the course number: 300 The id: 300 corresponds to Design and Analysis of Algorithms The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 3 Enter the course number: 325 The id: 325 does not correspond to any course in the department The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 6 Exiting the program
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
