代码太乱了,当自己写时,懵逼了

来源:6-2 学生选课---判断 Set 中课程是否存在

CDH_辉

2018-11-18 17:29


// 创建学生对象并选课

public void createStudentAndSelectCours() {

//创建一个学生对象

student = new Student("1", "小明");

System.out.println("欢迎学生:" + student.name + "选课!");

//创建一个Scanner对象,用来接收从键盘输入的课程ID

Scanner console = new Scanner(System.in);

for (int i = 0; i < 3; i++) {

System.out.println("请输入课程ID");

String courseId = console.next();

for (Course cr : coursesToSelect) {

if(cr.id.equals(courseId)) {

student.courses.add(cr);        //这里报错了,


}

}

}

}

报错原因:

The method add(Collection_ArrayList.Course) in the type Set<Course> is not applicable for the arguments (CollectionMethod.Course)

写回答 关注

1回答

  • 雀雀you
    2018-11-19 19:45:49

    只看这个类,没办法解决问题啊。据我看你的这个异常信息,大概是非法参数异常。你的方法需要什么类型的参数?

    信息提示你是在调用add方法时出现的问题,在本类中找不到错误,就应该顺藤摸瓜找到方法定义处继续找。

Java入门第三季

Java中你必须懂得常用技能,不容错过的精彩,快来加入吧

409777 学习 · 4339 问题

查看课程

相似问题