Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the simple Student status Management system by Java

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

这篇文章给大家分享的是有关Java怎么实现简易学籍管理系统的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

具体内容如下

1、我们先来讲讲什么是泛型化编程

package 学生管理系统; import java.util.ArrayList;import java.util.List; /* * 进行泛型化编程 * @autor:pcb * */public class TestGeneric { //进行泛型化编程,规定类型。 public List courses; public TestGeneric() { this.courses = new ArrayList(); } public void testAdd() { CourseClass cr1 = new CourseClass("1","大学语文"); courses.add(cr1); //泛型集合中不能添加规定意外的对象 //courses.add("能否添加一些奇怪的东西"); CourseClass cr2 = new CourseClass("2","Java基础"); courses.add(cr2); } public void testForEach() { //进行泛型之后,可直接利用它规定的类型及其子类型直接进行访问 for(CourseClass cr:courses) { System.out.println(cr.id+":"+cr.name); } } //泛型集合可以添加泛型的子类型的对象实例 public void testChild() { ChildCourse ccr = new ChildCourse(); ccr.id = "3"; ccr.name = "我是子类的课程实例对象"; courses.add(ccr); } //泛型必须使用包装类型进行创建,例如:int和integer public void testBaic() { List list = new ArrayList(); list.add(1); System.out.println("基本类型必须使用包装类作为泛型!"+list.get(0)); } public static void main(String[] args) { TestGeneric tg = new TestGeneric(); tg.testAdd(); tg.testForEach(); tg.testChild(); tg.testForEach(); tg.testBaic(); //tg.testForEach(); }}

2、我们开始进行管理系统的创建,创建一个学生类和一个课程类

package 学生管理系统; import java.util.HashSet;import java.util.Set;public class StudentsClass implements Comparable { public String id; public String name; public Set courses; public StudentsClass(String id,String name){ this.id=id; this.name=name; this.courses=new HashSet(); } @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 StudentsClass)) 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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report