I'm working on a project where I have to test to make sure certain code will meet user expectations. The only part I was supposed to do is write the code for GetCourseByCourseID. Everything else was given to me. I've written the code and run the program. The program runs, but it doesn't display anything. What do I need to do?
public class Course {
public Course(String id, String title, int creditHours, String description, String prerequisiteCourse)
{
this.CourseID = id;
this.CourseTitle = title;
this.CreditHours = creditHours;
this.Description = description;
this.PrerequisiteCourse = prerequisiteCourse;
}
public String CourseID;
public String CourseTitle;
public int CreditHours;
public String Description;
public String PrerequisiteCourse;
}
public 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;
}
}
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 != "CIS 400")
System.out.println("ERROR - GetCourseByCourseIDTestWhenCourseExists(): Returned CourseID Not equal (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");
}
}
This is for a class. I asked my professor why it wasn't showing up and he said he wasn't familiar with java and that I should use visual basic. I personally hate visual basic (bad experience with it in a prior class) and I would love to know how it works in java! I have looked everywhere for 2 hours and not found anything! Please help!