package miooc;import java.util.ArrayList;import java.util.Scanner;;/** * 测试学生选课的类 * Meng7y * 2017年6月27日 19:25:44 */public class TestStudent { //《?》可以用List的引用类型和ArrayList类型的引用。有什么区别吗 public ArrayList<Course> courses1; public TestStudent() { this.courses1 = new ArrayList<Course>(); Course cr = new Course("1", "java"); courses1.add(cr); Course cr1 = new Course("2", "c"); courses1.add(cr1); Course cr2 = new Course("3", "c++"); courses1.add(cr2); Course cr3 = new Course("4", "c#"); courses1.add(cr3); } public void IteratorCourse(){ System.out.println("有以下可选课程!"); for(Course cr:courses1){ System.out.println("课程"+cr.getId()+":"+cr.getName()); } } public void student(){ Student sd = new Student("1", "小明"); System.out.println("欢迎"+sd.getName()+"同学选课!"); System.out.println("请输入要选择的课程序号(请选择三门课程!)"); @SuppressWarnings("resource") Scanner input = new Scanner(System.in); for(int i = 0; i < 3; i++){ System.out.println("请输入课程的序号!"); String id = input.nextLine(); for(Course cr:courses1){ if(cr.getId().equals(id)){ sd.courses.add(cr); } } } System.out.println("选择的是如下的三门课程:"); for(Course course:sd.courses){ System.out.println(course.getId()+":"+course.getName()); } } public static void main(String[] args) { // TODO Auto-generated method stub TestStudent ts = new TestStudent(); ts.IteratorCourse(); ts.student(); }}
添加回答
举报
0/150
提交
取消