java简易学生管理系统,学生学籍管理系统java课程设计
本文实例为大家分享了爪哇实现简易学籍管理系统的具体代码,供大家参考,具体内容如下
1、我们先来讲讲什么是泛型化编程
包裹学生管理系统;导入Java。util。ArrayList导入Java。util。列表;/** 进行泛型化编程* @ autor:PCB * */public class test generic {//进行泛型化编程,规定类型公共列表课程班课程;公共测试泛型(){ this。courses=new ArrayList课程类();} public void testAdd(){ course class cr1=new course class( 1 ,大学语文);课程。添加(cr1);//泛型集合中不能添加规定意外的对象//courses.add(能否添加一些奇怪的东西);课程类别cr2=新的课程类( 2 , Java基础);课程。添加(cr2);} public void testForEach() { //进行泛型之后,可直接利用它规定的类型及其子类型直接进行访问对于(课程类Cr :课程){ system。出去。println(Cr。id : Cr。姓名);} } //泛型集合可以添加泛型的子类型的对象实例公共void test child(){ child course CCR=new child course();ccr.id= 3ccr.name=我是子类的课程实例对象;课程。添加(CCR);} //泛型必须使用包装类型进行创建,例如:int和整数公共void测试BAIC(){ list integer list=new ArrayListInteger();列表。添加(1);System.out.println(基本类型必须使用包装类作为泛型!列表。get(0));}公共静态void main(String[]args){ test generic TG=new test generic();TG。testadd();TG。testforeach();TG。测试子();TG。testforeach();TG。测试BAIC();//TG。testforeach();}}2、我们开始进行管理系统的创建,创建一个学生类和一个课程类
包裹学生管理系统;导入Java。util。hashset导入Java。util。设置;公共班级学生班级实现可比较的学生类{公共字符串id公共字符串名称;公共SetCourseClass课程;public StudentsClass(字符串id,字符串名称){ this。id=id这个。name=namethis。courses=new HashSetCourseClass();} @ Override public int hashCode(){ final int prime=31;int result=1;result=prime * result((name==null)?0 :名称。hashcode());返回结果;} @覆盖public boolean equals(Object obj){ if(this==obj)返回trueif (obj==null)返回错误的如果(!学生的实例
s)) return false; StudentsClass other = (StudentsClass) obj; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; return true; } public int compareTo(StudentsClass o) { return this.id.compareTo(o.id); }}package 学生管理系统; public class CourseClass { public String id; public String name; public CourseClass(String id,String name){ this.id=id; this.name=name; } public CourseClass() { } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof CourseClass)) return false; CourseClass other = (CourseClass) obj; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; return true; }}3、利用List进行增加课程,删除课程,修改课程等的操作
package 学生管理系统;import java.util.ArrayList;import java.util.Arrays;import java.util.Iterator;import java.util.List; public class ListTest { //创建public List coursesToSelect; //构造器 public ListTest(){ this.coursesToSelect = new ArrayList(); } public void testAdd(){ //加课 CourseClass cr1 = new CourseClass("1","数据结构"); coursesToSelect.add(cr1); CourseClass temp = (CourseClass)coursesToSelect.get(0); System.out.println("添加了课程:"+temp.id+":"+temp.name); CourseClass cr2 = new CourseClass("2","c语言"); coursesToSelect.add(0, cr2); CourseClass temp2 = (CourseClass)coursesToSelect.get(0); System.out.println("添加了课程:"+temp2.id+":"+temp2.name); CourseClass[] Course={new CourseClass("3","离散数学"),new CourseClass("4","汇编语言")}; coursesToSelect.addAll(Arrays.asList(Course)); CourseClass temp3 = (CourseClass)coursesToSelect.get(2); CourseClass temp4 = (CourseClass)coursesToSelect.get(3); System.out.println("添加了两门课程:"+temp3.id+":"+temp3.name+";"+temp4.id+":"+temp4.name); CourseClass[] Course1= {new CourseClass("5","高等数学"),new CourseClass("6","大学英语")}; coursesToSelect.addAll(2, Arrays.asList(Course1)); CourseClass temp5 = (CourseClass)coursesToSelect.get(2); CourseClass temp6 = (CourseClass)coursesToSelect.get(3); System.out.println("添加了两门课程:"+temp5.id+":"+temp5.name+";"+temp6.id+":"+temp6.name); } public void test() { int size = coursesToSelect.size(); for(int i=0;i<size;i++) { //进行强制类型转化 CourseClass cr = (CourseClass)coursesToSelect.get(i); System.out.println("课程"+i+":"+cr.id+":"+cr.name); } } //迭代器输入方法 public void testIterator() { Iterator it = coursesToSelect.iterator(); System.out.println("可选择的课程(通过迭代器访问):"); while(it.hasNext()) { CourseClass cr = (CourseClass) it.next(); System.out.println("课程"+":"+cr.id+":"+cr.name); } } //利用foreach语句进行遍历 public void testForEach() { System.out.println("可选择的课程(通过FOREACH访问):"); for(Object obj:coursesToSelect) { CourseClass cr = (CourseClass) obj; System.out.println("课程"+":"+cr.id+":"+cr.name); } } //进行修改操作 public void testModify() { coursesToSelect.set(4, new CourseClass("7","毛概")); } //利用对象进行删除操作 public void testRmove1() { System.out.println("通过对象进行删除"); CourseClass cr = (CourseClass) coursesToSelect.get(4); System.out.println("我是课程:"+cr.id+":"+cr.name); coursesToSelect.remove(cr); System.out.println("成功删除课程!!"); testForEach(); } //利用索引值进行删除操作 public void testRmove2() {// CourseClass cr = (CourseClass) coursesToSelect.get(4);// System.out.println("我是课程:"+cr.id+":"+cr.name); System.out.println("通过索引值进行删除"); coursesToSelect.remove(4); System.out.println("成功删除课程!!"); testForEach(); } //进行删除,删除多位置的方法操作 public void testRmove3() { System.out.println("删除4位置和5位置的课程"); CourseClass [] Course={(CourseClass) coursesToSelect.get(4),(CourseClass) coursesToSelect.get(5)}; //将Course数组转化成一个集合传递进去 coursesToSelect.removeAll(Arrays.asList(Course)); System.out.println("成功删除课程!!"); testForEach(); } public static void main(String[] args) { ListTest it = new ListTest(); it.testAdd(); it.test(); //it.testIterator(); //it.testForEach(); //it.testModify(); //it.testForEach(); //it.testRmove2(); it.testRmove3(); }}
4、利用set集合进行删除,添加,查询操作
package 学生管理系统; import java.util.ArrayList;import java.util.Arrays;import java.util.List;import java.util.Scanner; public class SetTest { //创建 public List <CourseClass> coursesToSelect; //向屏幕读取 private Scanner console; public StudentsClass student; //进行构造 public SetTest() { coursesToSelect = new ArrayList<CourseClass>(); console = new Scanner(System.in); } public void testAdd(){ //加课 CourseClass cr1 = new CourseClass("1","数据结构"); coursesToSelect.add(cr1); CourseClass temp = (CourseClass)coursesToSelect.get(0); //System.out.println("添加了课程:"+temp.id+":"+temp.name); CourseClass cr2 = new CourseClass("2","c语言"); coursesToSelect.add(0, cr2); CourseClass temp2 = (CourseClass)coursesToSelect.get(0); //System.out.println("添加了课程:"+temp2.id+":"+temp2.name); CourseClass[] Course={new CourseClass("3","离散数学"),new CourseClass("4","汇编语言")}; coursesToSelect.addAll(Arrays.asList(Course)); CourseClass temp3 = (CourseClass)coursesToSelect.get(2); CourseClass temp4 = (CourseClass)coursesToSelect.get(3); //System.out.println("添加了两门课程:"+temp3.id+":"+temp3.name+";"+temp4.id+":"+temp4.name); CourseClass[] Course1= {new CourseClass("5","高等数学"),new CourseClass("6","大学英语")}; coursesToSelect.addAll(2, Arrays.asList(Course1)); CourseClass temp5 = (CourseClass)coursesToSelect.get(2); CourseClass temp6 = (CourseClass)coursesToSelect.get(3); //System.out.println("添加了两门课程:"+temp5.id+":"+temp5.name+";"+temp6.id+":"+temp6.name); } public void testForEach() { System.out.println("可选择的课程(通过FOREACH访问):"); for(Object obj:coursesToSelect) { CourseClass cr = (CourseClass) obj; System.out.println("课程"+":"+cr.id+":"+cr.name); } } //查询是否包含此课程 public void testListContains() { CourseClass course = coursesToSelect.get(0); System.out.println("取得课程:"+course.name); System.out.println("备选课程是否包含课程:"+course.name+"," +coursesToSelect.contains(course)); System.out.println("请输入课程名称:"); String name = console.next(); CourseClass course2 = new CourseClass(); course2.name = name; System.out.println("新创建课程:"+course2.name); System.out.println("备选课程是否包含课程:"+course2.name+"," +coursesToSelect.contains(course2)); //indexof来求出索引 if(coursesToSelect.contains(course2)) { System.out.println("课程:"+course2.name+"的索引位置为:"+ coursesToSelect.indexOf(course2)); } } public void creatStudentAndSelect() { //创建一个学生对象 student = new StudentsClass("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(CourseClass cr :coursesToSelect) { if(cr.id.equals(courseId)) { student.courses.add(cr); student.courses.add(null); student.courses.add(cr); } } } } //测试Set的contains方法 public void testSetContains() { System.out.println("请输入学生已选的课程名:"); String name = console.next(); &n
郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。