Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this assignment, you will design and implement a tool which will determine if

ID: 3707219 • Letter: I

Question

In this assignment, you will design and implement a tool which will determine if a student can enrol in a specific course based on courses he/she has taken so far. You are given few files, namely, Syllabus.txt containing information about various courses, and some Request.txt files (i.e. Request1.txt, Request2.txt, etc.). Each of these files contains one student enrollement request information (courses completed so far and courses he/she wishes to enrol in). Four of these files are provided with the assignment; however, any other similar files can be given and you should expect that your program will be tested with other Request.txt files. You will parse these files to extract course information and will produce an outcome for each of the course student wants to enrol in. The outcome for each course could be one of the below mentioned options where X represents the courseID, P represents coursID for pre-requisite and C represents courseID for co-requisite.

a) Student can enrol in X course as he/she has completed the pre-requisite P.
b) Student can enrol in X course as he/she is enroling for the co-requisite C.
c) Student can’t enrol in X course as he/she doesn’t have sufficient background needed.

You can assume that every course can have minimum of zero and maximum of one pre-requisite as well as co-requisite. You can also assume that the courses will be listed from basic to advanced to help parse them easily. Request.txt contains a word “Finished” on first line, followed by courseID of those courses. Another word “Requested” after the above information followed by the respective courseIDs. Syllabus.txt contains courseID along with course name (one word seperated by _) and credits assigned to that course. Next two lines will have P and C indicating pre-requisite and co-requisite respectively fo this course. This set of information is repeated for all the available courses. A sample Syllabus.txt file is depicted in Figure 1 and a sample Request.txt is depicted in Figure 2. A detailed description of all the details that you have to implement for this assignment is avaialble after the two figures.

I) Create an interface named DirectlyRelatable which has a boolean method called isDirectlyRelated (Course C) where C is a object of type Course described in the next part.

II) The Course class, which must implement the DirectlyRelatable interface, has the following attributes: a courseID (String type), a courseName (String type), a credit (double type), a preReqID

(String type), coReqID (String type). It is assumed that course name is always recorded as a single word (_ is used to combine multiple words). It is also assumed that no two courses can have the same courseID. You are required to write the implementation of the Course class. Besides the usual mutator and accessor methods (i.e. getCourseID(), setCoursename()) the class must also have the following:

a) Parameterized constructor that accepts five values and initializes courseID, courseName, credit, preReqID, coReqID to these passed values;

b) Copy constructor, which takes in two parameters, a Course object and a String value. The newly created object will be assigned all the attributes of the passed object, with the exception of the courseID. courseID is assigned the value passed as the second parameter to the constructor. It is always assumed that this value will correspond to the unique courseID rule;

c) clone() method. This method will prompt the user to enter a new courseID, then creates and returns a clone of the calling object with the exception of the courseID, which is assigned the value entered by the user;

d) Additionally, the class should have a toString() and an equals() methods. Two courses are equal if they have the same attributes, with the exception of the courseID, which could be different.

e) This class needs to implement the interface from part I. The method isDirectlyRelated that takes in another Course object C and should return true if C is pre-requisite or co-requisite of the current course object, or vise versa (hence the courses are directly related); otherwise it returns false.

III) The CourseList class has the following:

(a) An inner class called CourseNode. This class has the following:
i. Two private attributes: an object of Course and a pointer to a CourseNode object;

ii. A default constructor, which assigns both attributes to null;
iii. A parameterized constructor that accepts two parameters, a Course object and a CourseNode

object, then initializes the attributes accordingly; iv. A copy constructor;

v. A clone() method;
vi. Othermutatorandaccessormethods.

(b) A private attribute called head, which should point to the first node in this list object;

(c) Aprivateattributecalledsize,whichalwaysindicatesthecurrentsizeofthelist(howmanynodes are in the list);

(d) A default constructor, which creates an empty list;

(e) A copy constructor, which accepts a CourseList object and creates a copy of it;

(f) A method called addToStart(), which accepts one parameter, an object from Course class and then creates a node with that passed object and inserts this node at the head of the list;

(g) A method called insertAtIndex(), which accepts two parameters, an object from Course class, and an integer representing an index. If the index is not valid (a valid index must have a value between 0 and size-1), the method must throw a NoSuchElementException and terminate the program. If the index is valid, then the method creates a node with the passed Course object and inserts this node at the given index. The method must properly handle all special cases;

(h) A method called deleteFromIndex(), which accepts one integer parameter representing an index. Again, if the index is not valid, the method must throw a NoSuchElementException and terminate the program. Otherwise; the node pointed by that index is deleted from the list. The method must properly handle all special cases;

(i) A method called deleteFromStart(), which deletes the first node in the list (the one pointed by head). All special cases must be properly handled.

(j) A method called replaceAtIndex(), which accepts two parameters, an object from Course class, and an integer representing an index. If the index is not valid, the method simply returns; otherwise the object in the node at the passed index is to be replaced by the passed object;

(k) A method called find(), which accepts one parameter of type String representing a courseID. The method then searches the list for a courseNode with with that courseID. If such an object is found, then the method returns a pointer to that courseNode; otherwise, method returns null. The method must keep track of how many iterations were made before the search finally finds the course or concludes that it is not in the list;

(l) A method called contains(), which accepts one parameter of type String representing a courseID. The method returns true if a course with that courseID is in the list; otherwise, the method returns false;

(m) A method called equals(), which accepts one parameter of type Syllabus. The method returns true if the two lists contain similar courses; otherwise the method returns false. Recall that two Course objects are equal if they have the same values with the exception of the courseID, which can, and actually is expected to be, different.

Finally, here are some general rules that you must consider when implementing the above methods: -Whenever a node is added or deleted, the list size must be adjusted accordingly;
-All special cases must be handled, whether or not the method description explicitly states that; -All clone() and copy constructors must perform a deep copy; no shallow copies are allowed;

-If any of your methods allows a privacy leak, you must clearly place a comment at the beginning of the method 1) indicating that this method may result in a privacy leak 2) explaining reason behind the privacy leak. Please keep in mind that you are not required to implement these proposals;

IV) Now, you are required to write a public class called EnrolmentResults. In the main() method, you must do the following:

(a) Create at least two empty lists from the CourseList class (needed for copy constructor III (e));

(b) OpentheSyllabus.txtfile,andreaditscontentslinebyline.Usetheserecordstoinitializeoneof the CourseList objects you created above. You can use the addToStart() method to insert the read objects into the list. However, the list should not have any duplicate records, so if the input file has duplicate entries, which is the case in the file provided with the assignment for instance, your code must handle this case so that each record is inserted in the list only once;

(c) OpenaRequest.txtfile(prompttheusertoenterthenameofthefilethatneedtobeprocessed; i.e. Request3.txt) and create ArrayLists from the contents then iterate through each of the courses the student wants to enroll in. Process each of the courses and print the outcome whether student will be able to enroll or not. A sample output for a given file is mentioned below. Again, your program should ask for the file names as your program will be tested against similar input files;

(d) Prompt the user to enter a few courseIDs and search the list that you created from the input file for these values. Make sure to display the number of iterations performed;

(e) Following that, you must create enough objects to test each of the constructors/methods of your classes. The details of this part are left as open to you. You can do whatever you wish as long as

your methods are being tested including some of the special cases. You should also make sure to test the isDirectlyRelated() method.

Explanation / Answer

import java.util.Scanner;

interface DirectlyRelatable{

boolean isDirectlyRelated (Course C);

}

public class Course implements DirectlyRelatable, Cloneable{

String courseID;

String courseName;

double credit;

String preReqID;

String coReqID;

Course(String cID, String cName,double credit, String preID, String coID){

this.courseID = cID;

this.courseName = cName;

this.credit = credit;

this.preReqID = preID;

this.coReqID = coID;

}

Course(Course c, String cID){

c.courseID = cID;

c.courseName = this.courseName;

c.credit = this.credit;

c.preReqID = this.preReqID;

c.coReqID = this.coReqID;

}

public Object clone() throws CloneNotSupportedException{  

Scanner sc=new Scanner(System.in);

System.out.println("Please enter the course ID");

String courseID = sc.nextLine();

this.setCourseID(courseID);

return super.clone();  

}  

public String toString(){

return this.toString();

}

public String getCourseID() {

return courseID;

}

public void setCourseID(String courseID) {

this.courseID = courseID;

}

public String getCourseName() {

return courseName;

}

public void setCourseName(String courseName) {

this.courseName = courseName;

}

public double getCredit() {

return credit;

}

public void setCredit(double credit) {

this.credit = credit;

}

public String getPreReqID() {

return preReqID;

}

public void setPreReqID(String preReqID) {

this.preReqID = preReqID;

}

public String getCoReqID() {

return coReqID;

}

public void setCoReqID(String coReqID) {

this.coReqID = coReqID;

}

@Override

public boolean isDirectlyRelated(Course C) {

// TODO Auto-generated method stub

return false;

}

}