Java Help

profileachops27
week_7_work.docx

Java – GetCourseByCourseID()

Code:

class CourseList

{

public Course[] CourseArray =

{

new Course ("CIS 400", "OO Analysis & Design", 4, "Important class", "CIS 110") ,

new Course ("CIS 150A" , "VB.NET Programming", 4, "Good Introduction to programming", "CIS 100") ,

new Course ("CIS 150B", "C# Programming with labs", 4, "Follow-up to CIS 100", "CIS 100")

};

public Course GetCourseByCourseID(String id)

{

for (Course course : CourseArray)

if ( course.CourseID == id)

return course;

return null;

}

}

The code below is supposed to go into the code above to give some kind of a message. I need this added and the code ran and screen shots take showing that the code is working.

Java CourseListTest Code

public class CourseListTest {

public static void main(String[] args) {

GetCourseByCourseIDTestWhenCourseExists();

GetCourseByCourseIDTestWhenCourseDoesNotExist();

}

public static void GetCourseByCourseIDTestWhenCourseExists() {

CourseList myCourseList = new CourseList();

Course myCourse = myCourseList.GetCourseByCourseID("CIS 400");

If (myCourse.CourseID == null) {

System.out.println(“ ERROR - GetCourseByCourseIDTestWhenCourseExists(): Returned null");

}

else {

System.out.println(“GetCourseByCourseIDTestWhenCourseExists(): Found a match using CIS 400”);

}

public static void GetCourseByCourseIDTestWhenCourseDoesNotExist() {

CourseList myCourseList = new CourseList();

Course myCourse = myCourseList.GetCourseByCourseID(“CIS 101”);

if (myCourse != null) {

System.out.println(“ERROR - GetCourseByCourseIDTestWhenCourseDoesNotExist(): should have returned null”);

}

else {

System.out.println(“GetCourseByCourseIDTestWhenCourseDoesNotExist(): Returned null”);

}

}

}