栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java基于集合的学生信息管理系统(含说明书)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java基于集合的学生信息管理系统(含说明书)

Java基于集合的学生信息管理系统

清内存,希望各位大佬别介意

ArrayList

学生类

package 大作业;

public class Student {
	String id,name,phone,dormitory,classroom;
	Student(){
	}
	Student(String id,String name,String phone,String dormitory,String classroom){
		this.id=id;
		this.name=name;
		this.phone=phone;
		this.dormitory=dormitory;
		this.classroom=classroom;
	}
	public void setId(String id) {
		this.id=id;
	}
	String getId(){
		return id;
	}
	public void setName(String name) {
		this.name=name;
	}
	String getName(){
		return name;
	}
	public void setPhone(String phone) {
		this.phone=phone;
	}	
	String getPhone(){
		return phone;
	}
	public void setDormitory(String dormitory) {
		this.dormitory=dormitory;
	}
	String getDormitory(){
		return dormitory;
	}
	public void setClassroom(String classroom) {
		this.classroom=classroom;
	}
	String getClassroom(){
		return classroom;
	}
	String getMessage() {
		return "学号:"+id+" 姓名:"+name+" 电话号码:"+phone+" 宿舍号:"+dormitory+" 班级:"+classroom;
	}
}

Manage类

package 大作业;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
import java.io.*;
public class Manage {
	public static void main(String[] args) {
		ArrayList array=new ArrayList();
        //读取文件
		File fr=new File("学生档案.txt");
		try {        
			Reader in=new FileReader(fr);
			BufferedReader br=new BufferedReader(in);
			String b=null;
			int count=0;
			while((b=br.readLine())!=null) {	
				count++;
				String str[]=b.split(",");
				Student st=new Student(str[0],str[1],str[2],str[3],str[4]);
				array.add(st);				
			}	
			//System.out.println("档案学生个数"+count);
			//System.out.println("集合中学生个数"+array.size());
		}
		catch(Exception ioe) {
			System.out.println(ioe);
		}
		while(true){ //while(true)就是无限循环语句。因为括号中的条件为true,所以永远不会跳出循环,除非语句块中有break语句才都能跳出循环。
			System.out.println("----欢迎来到学生管理系统----");
			System.out.println("1.添加学生信息");
			System.out.println("2.删除学生信息");
			System.out.println("3.修改学生信息");
			System.out.println("4.查询学生信息");
			System.out.println("5.浏览所有学生信息");
			System.out.println("6.退出");
			System.out.println("请输入你的选择:");
			Scanner sc=new Scanner(System.in);
			String line=sc.nextLine();
			switch(line) {
			case"1":
				addstudent(array);
				write(array);
				break;
			case"2":
				remove(array);
				write(array);
				break;
			case"3":
				change(array);
				write(array);
				break;
			case"4":
				find(array);
				write(array);
				break;
			case"5":
				System.out.println("以下为所有学生的基本信息");
				Iterator iter=array.iterator();//用迭代器遍历排序后的list
				while(iter.hasNext()) {
					Student st1=iter.next();
					System.out.println(st1.getMessage());
				}
				break;
			case"6":
				System.out.println("谢谢使用!");
				System.exit(0); //system.exit(int status);正常退出。status为0时为正常退出程序,也就是结束当前正在运行中的java虚拟机。
			}		
		}
	}
//增加学生信息
	public static void addstudent(ArrayList array) {
		int i,k=0;
		Scanner sc1=new Scanner(System.in);
		System.out.println("请输入学号:");
		String id=sc1.nextLine();
		for(i=0;i array) {
		Scanner sc1=new Scanner(System.in);
		System.out.println("请输入要删除学生的学号:");
		String id=sc1.nextLine();
		int i,k;
		for(i=k=0;i array) {
		Scanner sc1=new Scanner(System.in);
		System.out.println("请输入要修改学生的学号:");
		String id=sc1.nextLine();
		int i,k;
		for(i=k=0;i array) {
		int i,k=0;
		Scanner sc1=new Scanner(System.in);
		System.out.println("请输入查询学生的学号:");
		String id=sc1.nextLine();	
		for(i=0;i array) {
		File fw=new File("学生档案.txt");
		try {	
			Writer out=new FileWriter(fw);
			BufferedWriter bw=new BufferedWriter(out);		
			Iterator iter=array.iterator();//用迭代器遍历排序后的list
			while(iter.hasNext()) {
				Student st=iter.next();
				String ss=st.id+","+st.name+","+st.phone+","+st.dormitory+","+st.classroom;
				System.out.println(ss);
				bw.write(ss);
				bw.newline();
			}			
			bw.close();
			out.close();
		}
		catch(Exception ioe) {
			System.out.println(ioe);
		}
	}
}

说明书链接: https://pan.baidu.com/s/17CkrL28M2rlvIQC_-vtVlA 提取码: e1ve 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/340577.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号