package ⅣCollectionMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class SetTest {
public List<Course> coursesToSelect;
public SetTest(){
coursesToSelect = new ArrayList<Course>();
}
public void testAdd(){
Course[] courses = {new Course("1.","大学英语"),new Course("2.","高等数学"),new Course("3.","微机原理"),new Course("4.","数字电子技术"),new Course("5.","模拟电子技术"),new Course("6.","自动控制技术")};
}
public void testForEach(){
System.out.println("有如下课程待选(通过for each访问):");
for (Course cr:coursesToSelect){
System.out.println("课程:"+ cr.id + "." + cr.name);
}
}
public static void main(String[] args){
SetTest st = new SetTest();
st.testAdd();
st.testForEach();
//创建一个学生对象
Student 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:st.coursesToSelect){
if (cr.id.equals(courseId)){
student.courses.add(cr);
}
}
}
st.testForEachForSet(student);
}
public void testForEachForSet(Student student){
System.out.println(111111);
//打印输出,学生所选课程!
for (Course cr : student.courses){
System.out.println(student.name + "选择了课程:"+ cr.id + "."+cr.name);
}
}
}