need to answer question1-6 plz!! (especially question6) please read it carefully! A bit different to the question alread

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

need to answer question1-6 plz!! (especially question6) please read it carefully! A bit different to the question alread

Post by answerhappygod »

need to answer question1-6 plz!! (especially question6) please
read it carefully! A bit different to the question already had
in answers ;))
Here are a few extra instructions:
Do not forget to write tests for all the code of all the
classes.
Give meaningful names to your variables so we can easily know
what each variable
is used for in your program.
Put comments in your code (in English!) to explain WHAT your
code is doing and also
to explain HOW your program is doing it.
Make sure all your code is properly indented (formatted). Your
code should be
beautiful to read.
Need To Answer Question1 6 Plz Especially Question6 Please Read It Carefully A Bit Different To The Question Alread 1
Need To Answer Question1 6 Plz Especially Question6 Please Read It Carefully A Bit Different To The Question Alread 1 (123.3 KiB) Viewed 24 times
Need To Answer Question1 6 Plz Especially Question6 Please Read It Carefully A Bit Different To The Question Alread 2
Need To Answer Question1 6 Plz Especially Question6 Please Read It Carefully A Bit Different To The Question Alread 2 (122.21 KiB) Viewed 24 times
Question 1 Create a Course class with the following UML specification: 1 Course | - code: String | - title: String | - prerequisite: Course 1 | + Course (String code, String title, Course prerequisite) | + getCode(): String | + getTitle(): String 1 | + getPreRequisite(): Course 1 + isRequired(): boolean | + testCourse() : void where: code: is an instance variable storing the code of the course. title: is an instance variable storing the title of the course. prerequisite: is an instance variable storing the pre-requisite course of the course and a prerequisite is another course (in our homework setting, a course always has only one pre-requisite course and the pre-requisite course cannot be null. If the pre- requisite course is null, the constructor should print a message of “pre-requisite course cannot be null!" and return directly). isRequired: is a method that returns a boolean value to indicate whether a course is required or not. One course could either be a required course or an elective course. Some courses are required, while the others are not required. Also add to your program a Start class with a main method that calls the testCourse method of the Course class. (What kinds of tests can you write inside the testCourse method?)
Question 2 Add a class MajorRequired to your program. MajorRequired are courses that is required for every student. The constructor for the MajorRequired class takes the code, title and pre-requisite of the course as arguments. The pre-requisite course of a major required course should also be a major required course (type should be MajorRequired and pre-requisite course cannot be null). MajorRequired class should also contain a static method called testMajorRequired() that contains the unit tests of MajorRequired class. (What kinds of tests can you write inside the testMajorRequired method?) Do not forget to change the main method of the Start class to run the unit tests of the new MajorRequired class. Question 3 Add a class MajorElective to your program. MajorElective are courses that are elective for every student. The constructor for the MajorElective class takes the code, string and pre-requisite of the course as arguments. The pre-requisite course of a major elective course should be a major required course (type should be Major Required and pre-requisite course cannot be null). a Your MajorElective class should also contain static method called testMajorElective () that contains the unit tests of MajorElective class. (What kinds of tests can you write inside the testMajorElective method?) Do not forget to change the main method of the Start class to run the unit tests of the new MajorElective class.
Question 4 The problem with the MajorRequired class above is that the constructor takes a MajorRequired object as the third argument and it cannot be null. This means that, to create a major required course, you need to already have another major required course. In turn this means that you cannot create any major required course at all, because you cannot create the first one! To solve this problem, add to your program a Base class with the following UML specification: 1 1 Base +- - code: String 1 title: String +- | + Base (String code, String title) | + getCode (): String 1 getTitle(): String 1 getPrerequisite() : Base | + testBase() : void . Base courses do not necessarily have any pre-requisite, so the getPrerequisite method will return itself. Your Base class should also contain a static method called testBase () that contains the unit tests of Base class. Do not forget to change the main method of the Start class to run the unit tests of the new Base class.
Question 5 We now want to modify the code so that a base course can be the pre-requisite of other courses. To do this, add to your program a Learnable interface, which can be the pre-requisite of any other courses, with the following UML specification: I I «interface >> Learnable 1 | + getCode(): String | + getTitle(): String | + getPreRequisite(): Learnable I or Modify the course and Base classes so that they both implement the Learnable interface, and modify the course, MajorRequired and MajorElective so that a major required/elective course can now have a pre-requisite who is either a major required course base Once you have done this, add tests to: testMajorRequired method of the MajorRequired class: create a Base object and use that Base object to create a first MajorRequired object who has the base course as pre-requisite; then use that first Major Required object to create a second MajorRequired object who has the first major required course as pre-requisite. Test all the methods of the two MajorRequired objects. testMajorElective method of the MajorElective class: create a Base object and use that Base object to create a first MajorRequired object who has the base course as pre-requisite; then use that MajorRequired object to create a MajorElective object who has the major required course as pre-requisite. Test all the methods of the MajorElective object.
Question 6 We now want to be able to manipulate many courses together, not just one courses at a time. So add a ManyCourses class to your program with the following UML diagram: 1 Many Courses 1 - Courses: ArrayList I + Many Courses () 1 + addCourse (Learnable c): void | | + listCourses (): void 1 I + testManyCourses(): void I +-- The Courses instance variable is of type ArrayList which is a class provided to you by Java that you need to import into your program using: import java.util.ArrayList; You can then define the Courses instance variable like this: private ArrayList Courses; In the ManyCourses constructor you need to create a new ArrayList object and store it in the instance variable Courses, like this: this.courses = new ArrayList(); (if you forget to do this then the instance variable Courses will point at nothing and you will get an error when you run your program and you try to call a method of the nonexistent arraylist object). The addCourse method takes a course as argument and adds it to the arraylist. The listCourses method prints on the screen the course code and title, one by one, using a loop. Here is the code of the testMany Courses method: public static void testManyCourses () { Base b = new Base ("DS1001", "EntryCourse"); MajorRequired mrl = new Major Required ("DS200X", "OOP",b); MajorElective mel = new MajorElective ("DS300X","Data Mining",mr1); ManyCourses mc = new ManyCourses (); mc.addCourse (b); mc.addCourse (mrl); mc.addCourse (mel); mc.listCourses(); } Then the listCourses method should print: DS1001, EntryCourse DS200x, OOP DS300X, Data Mining Do not forget to change the main method of the Start class to run the unit tests of the new Many Courses class.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply