为什么我输入高等数学回车之后连带着拼音一块输出了。。。。
请输入学生已选的课程名称:
高等数学
新创建课程:gao'denggao'den高等数学
备选课程中是否包含课程:gao'denggao'den高等数学;false
请输入学生已选的课程名称:
高等数学
新创建课程:gao'denggao'den高等数学
备选课程中是否包含课程:gao'denggao'den高等数学;false
2015-04-18
package come.collection; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; public class testSet { public List <Course> coursesToSelect; public Scanner console; public Student student; public testSet(){ coursesToSelect = new ArrayList<Course>(); } public void testAdd(){ Course cr1 =new Course("1", "数据结构"); coursesToSelect.add(cr1); Course temp = (Course)coursesToSelect.get(0); //System.out.println("备选课程"+temp.id+" "+temp.name); Course cr2 = new Course("2","c语言"); coursesToSelect.add(0, cr2); Course temp2 = (Course)coursesToSelect.get(0); //System.out.println("备选课程"+temp2.id+" "+temp2.name); //Course cr11 =new Course("1", "数据结构"); //coursesToSelect.add(cr11); //Course temp0 = (Course)coursesToSelect.get(2); //System.out.println("备选课程"+temp0.id+" "+temp0.name); // Course cr3 = new Course("3","test"); // coursesToSelect.add(4, cr3); Course[] course = {new Course("3","计算机网络"),new Course("4","汇编语言")}; coursesToSelect.addAll(Arrays.asList(course)); Course temp3 = (Course)coursesToSelect.get(2); Course temp4 = (Course)coursesToSelect.get(3); //System.out.println("添加了两门课程:"+temp3.id+" "+temp3.name+";"+temp4.id+" "+temp4.name); Course[] course2 = {new Course("5","高等数学"),new Course("6","线性代数")}; coursesToSelect.addAll(2, Arrays.asList(course2)); Course temp5 = (Course)coursesToSelect.get(2); Course temp6 = (Course)coursesToSelect.get(3); //System.out.println("又添加了两门课程:"+temp5.id+" "+temp5.name+";"+temp6.id+" "+temp6.name); } public void testForEach(){ System.out.println("有如下课程(3):"); for(Object obj : coursesToSelect){ Course cr = (Course) obj; System.out.println("课程:"+cr.id+" "+cr.name); } } public void testForEachForSet(Student student){ System.out.println("共选择了:"+student.courses.size()+"门课程!"); for(Course cr : student.courses){ System.out.println("选择了课程:"+cr.id+" "+cr.name); } } //创建学生对象并选课 public void creatStudentAndSelectCourse(){ student =new Student("1","小明"); System.out.println("欢迎学生"+student.name+"选课!"); 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 ){ //Set中不能重复! if(cr.id.equals(courseID)){ student.courses.add(cr); student.courses.add(null); // student.courses.add(cr); } } } } public void testSetContains(){ System.out.println("请输入已选课程名称:"); console=new Scanner(System.in); String name = console.next(); Course course2 = new Course(); course2.name=name; System.out.println("新创建的课程:"+course2.name); System.out.println("备选课程中是否包含课程:"+course2.name+","+ student.courses.contains(course2)); } public static void main(String[] args) { // TODO Auto-generated method stub testSet st = new testSet(); st.testAdd(); st.testForEach(); st.creatStudentAndSelectCourse(); st.testSetContains(); /** // * 创建一个新的学生对象 // */ // Student student =new Student("1","小明"); // System.out.println("欢迎学生"+student.name+"选课!"); // 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 ){ // //Set中不能重复! // if(cr.id.equals(courseID)){ // student.courses.add(cr); // student.courses.add(null); //// student.courses.add(cr); } // st.testForEachForSet(student); }
举报