我正在做一个项目,我必须进行测试以确保某些代码能够满足用户的期望。我唯一要做的就是为 GetCourseByCourseID 编写代码。其他一切都给了我。我已经编写了代码并运行了程序。程序运行,但不显示任何内容。我需要做什么?
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");
}
}
这是为了上课。我问我的教授为什么它没有出现,他说他不熟悉 Java,我应该使用 Visual Basic。我个人讨厌visual basic(在之前的课程中使用它的经验很糟糕),我很想知道它在java中是如何工作的!我到处找了2个小时,没有找到任何东西!请帮忙!