************************************************************************************************************************

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

************************************************************************************************************************

Post by answerhappygod »

************************************************************************************************************************************
I already posted it many times BUT no one answered question 6!!!
We need to create a ManyCourses class!!!
please read it carefully! A bit different to the question
already had in answers ;))
will give a like!
************************************************************************************************************************************
 1
1 (117.79 KiB) Viewed 22 times
 2
2 (123.54 KiB) Viewed 22 times
 3
3 (98.04 KiB) Viewed 22 times
previous code
1. Start.java (The Main file):
--------------------------------------------------
package courseapp;
public class Start {
public static void main(String[] args) {
Base b = new Base("B001", "CS");

//Learnable interface created but functionality not
implemnted
//Code can be changed from here
Course course = new Course("C001","UML", null);
course.testCourse();

MajorRequired mr = new MajorRequired("MR001", "Java", null);
MajorRequired.testMajorRequired();


MajorElective me = new MajorElective("ME001", "AI", mr);
MajorElective.testMajorElective();
}
}
--------------------------------------------------
2. Base.java
--------------------------------------------------
package courseapp;
public class Base implements Learnable {
String code;
String title;

public Base(String code, String title) {
this.code = code;
this.title = title;
}

@Override
public String getCode() {
return code;
}
@Override
public String getTitle() {
return title;
}
@Override
public Base getPreRequisite() {
return this;
}


public void testBase() {
System.out.println("Course Code : " + this.getCode());
System.out.println("Course Title : " + this.getTitle());
}
}
--------------------------------------------------
3. Course.java
--------------------------------------------------
package courseapp;
public class Course implements Learnable {
String code;
String title;
Course preRequisite;
public Course(String code, String title, Course preRequisite)
{
if(preRequisite == null){
System.err.println("Prerequisite cannot be null value");
return;
}
this.code = code;
this.title = title;
this.preRequisite = preRequisite;
}
@Override
public String getCode() {
return code;
}
@Override
public String getTitle() {
return title;
}
@Override
public Course getPreRequisite() {
return preRequisite;
}

public boolean isRequired() {
return false;
}

public void testCourse() {
System.out.println("Course Code : " + this.getCode());
System.out.println("Course Title : " + this.getTitle());
}
}
--------------------------------------------------
4. MajorRequired.java
--------------------------------------------------
package courseapp;
public class MajorRequired {
String code;
String title;
MajorRequired preRequisite;
public MajorRequired(String code, String title, MajorRequired
preRequisite) {
this.code = code;
this.title = title;
this.preRequisite = preRequisite;
}
public static void testMajorRequired() {

}
}
--------------------------------------------------
5. MajorElective.java
--------------------------------------------------
package courseapp;
public class MajorElective {
String code;
String title;
MajorRequired preRequisite;
public MajorElective(String code, String title, MajorRequired
preRequisite) {
this.code = code;
this.title = title;
this.preRequisite = preRequisite;
}
public static void testMajorElective() {

}
}
--------------------------------------------------
6. Learnable.java
--------------------------------------------------
package courseapp;
public interface Learnable {
public String getCode();
public String getTitle();
public Learnable getPreRequisite();

}
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 () | + 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",mri); Many Courses 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.
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.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply