Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

hello , I need help with this java program I) Create an interface named DirectlyRelatable which has a boolean method called isDirectlyRelated (Course C) where

hello , I need help with this java program

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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What issue - specific security policies can you locate

Answered: 1 week ago

Question

1. Describe the types of power that effective leaders employ

Answered: 1 week ago