您的当前位置:首页正文

学生信息管理系统源代码

2020-11-14 来源:好走旅游网


学生信息管理系统源代码

import java.io.*;

class StuInfo {

public String name;

public int number;

public String sex;

public String age;

public String bir;

public String email;

public String addr;

public String tel;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getNumber() {

return number;

}

public void setNumber(int number) {

this.number = number;

}

public String getSex() {

return sex;

}

public void setSex(String sex) {

this.sex = sex;

}

public String getAge() {

return age;

}

public void setAge(String age) {

this.age = age;

}

public String getBir() {

return bir;

}

public void setBir(String bir) {

this.bir = bir;

}

public String getEmail() {

return email;

}

public void setEmail(String email ) {

this.email = email;

}

public String getAddr() {

return addr;

}

public void setAddr(String addr) {

this.addr = addr;

}

public String getTel() {

return tel;

}

public void setTel(String tel) {

this.tel = tel;

}

}

public class Student {

private static PrintStream out = System.out;

private static String filename = \"Stu.txt\";

private static int total = 0;

private static int rt = 0;//recyle length

private StuInfo[] stuInfos;

private StuInfo[] recycle;

BufferedReader buf = new InputStreamReader(System.in));//创建缓冲流

public Student(){

stuInfos = new StuInfo[11];

}

public void 信息录入(){

BufferedReader buf = new InputStreamReader(System.in));

try{

System.out.print(\"\\n请输入学生信息(以0结束)\\n\");

System.out.print(\"学号:\\n\");

StuInfo stu = new StuInfo();

BufferedReader(new

BufferedReader(new

stu.setNumber(Integer.parseInt(buf.readLine()));

while(stu.getNumber()!=0) {

System.out.print(\"姓名:\\n\\n\");

stu.setName(buf.readLine());

System.out.print(\"性别:\\n\\n\");

stu.setSex(buf.readLine());

System.out.print(\"年龄:\\n\\n\");

stu.setAge (buf.readLine());

System.out.print(\"生日:\\n\\n\");

stu.setBir(buf.readLine());

System.out.print(\"邮箱:\\n\\n\");

stu.setEmail(buf.readLine());

System.out.print(\"地址:\\n\\n\");

stu.setAddr(buf.readLine());

System.out.print(\"电话:\\n\\n\");

stu.setTel(buf.readLine());

//添加其他输入信息

stuInfos[total]=stu;

total++;

stu = new StuInfo();

System.out.print(\"\\n请输入下一个学生信息(以0结束)\\n\");

System.out.print(\"姓名:\\n\");

stu.setName(buf.readLine());

}

}catch(Exception e){

out.print(e);

}

}

public void 保存数据(){

try{

FileWriter fwr=new FileWriter(filename);

BufferedWriter fw = new BufferedWriter(fwr);

fw.write(total+\"\\r\\n\");

for(int k=0;kfw.write(stuInfos[k].getNumber()+\"\\r\\n\");

fw.write(stuInfos[k].getName()+\"\\r\\n\");

fw.write(stuInfos[k].getSex()+\"\\r\\n\");

fw.write(stuInfos[k].getAge()+\"\\r\\n\");

fw.write(stuInfos[k].getBir()+\"\\r\\n\");

fw.write(stuInfos[k].getEmail()+\"\\r\\n\");

fw.write(stuInfos[k].getAddr()+\"\\r\\n\");

fw.write(stuInfos[k].getTel()+\"\\r\\n\");

}

fw.write(rt+\"\\r\\n\");

for(int k=0;kfw.write(recycle[k].getNumber()+\"\\r\\n\");

fw.write(recycle[k].getName()+\"\\r\\n\");

fw.write(recycle[k].getSex()+\"\\r\\n\");

fw.write(recycle[k].getAge()+\"\\r\\n\");

fw.write(recycle[k].getBir()+\"\\r\\n\");

fw.write(recycle[k].getEmail()+\"\\r\\n\");

fw.write(recycle[k].getAddr()+\"\\r\\n\");

fw.write(recycle[k].getTel()+\"\\r\\n\");

}

fw.flush();

fw.close();

fwr.close();

System.out.println(\"\\n已保存数据!\");

}catch(Exception e){

out.print(e);

}

}

public void 读取数据(){

try{

FileReader fr = new FileReader(filename);

BufferedReader bfr = new BufferedReader(fr);

String buff = bfr.readLine();

if(buff != null) {

total = Integer.parseInt(buff);

}else{

total = 0;

}

StuInfo stu;

for(int i=0; istu = new StuInfo();

stu.setNumber(Integer.parseInt(bfr.readLine()));

stu.setName(bfr.readLine());

stu.setSex(bfr.readLine());

stu.setAge(bfr.readLine());

stu.setBir(bfr.readLine());

stu.setEmail(bfr.readLine());

stu.setAddr(bfr.readLine());

stu.setTel(bfr.readLine());

stuInfos[i]=stu;

}

buff = bfr.readLine();

if(buff!= null) {

rt = Integer.parseInt(buff);

}else{

rt = 0;

}

for(int i=0; istu = new StuInfo();

stu.setNumber(Integer.parseInt(bfr.readLine()));

stu.setName(bfr.readLine());

stu.setSex(bfr.readLine());

stu.setAge(bfr.readLine());

stu.setBir(bfr.readLine());

stu.setEmail(bfr.readLine());

stu.setAddr(bfr.readLine());

stu.setTel(bfr.readLine());

//补全

recycle[i]=stu;

}

// bfr.flush();

bfr.close();

fr.close();

System.out.println(\"读取成功\");

}catch(Exception e){

out.print(e);

}

}

public void 显示学生(StuInfo[] stus,int length){

try{

out.println(\"----------\");

for(int i=0;iout.println(\"学号:\"+stus[i].getNumber());

out.println(\"姓名:\"+stus[i].getName());

out.println(\"性别:\"+stus[i].getSex());

out.println(\"年龄:\"+stus[i].getAge());

out.println(\"生日:\"+stus[i].getBir());

out.println(\"邮箱:\"+stus[i].getEmail());

out.println(\"地址:\"+stus[i].getAddr());

out.println(\"电话:\"+stus[i].getTel());

//输出其他内容.....

out.println(\"----------\");

}

System.out.println(\"请按任意键继续\");

buf.read();//

}catch(Exception e){

out.print(e);

}

}

public void 姓名查询(String name){

StuInfo[] result = new StuInfo[11];

int r = 0;

for(int i=0;iif(stuInfos[i].getName().equals(name)){

result[r]=stuInfos[i];

r++;

}

}

if(r==0){

System.out.print(\"查找不到该学生!\");

//提示找不到学生

return;

}else{

显示学生(result, r);

}

}

public void 学号查询(String number ){

StuInfo[] result = new StuInfo[11];

int r = 0;

for(int i=0;iif(Integer.toString(stuInfos[i].getNumber()).equals(number)){

result[r]=stuInfos[i];

r++;//补全

}

}

if(r==0){

System.out.print(\"查找不到该学生!\");//提示找不到学生

}else{

显示学生(result, r);

}

}

public void 查找菜单(){//全字匹配

int choice;

try{

do{

System.out.println(\"查找界面\");//

System.out.println(\"1:按姓名查询\");

System.out.println(\"2:按学号查询\");

System.out.println(\"0:返回上级\");

BufferedReader InputStreamReader(System.in));

buf = new BufferedReader(new

choice = Integer.parseInt(buf.readLine());

switch(choice){

case 1:

System.out.println(\"请输入姓名\");//获得输入的姓名

String name = buf.readLine();

姓名查询(name);

break;

case 2:

System.out.println(\"请输入学号\");

String number = buf.readLine();

学号查询(number);//获得输入的学号

break;

default:

System.out.println(\"对不起,出现异常!\");

//异常:7

}

}while(choice!=0);

}catch(Exception e){

out.print(e);

}

}

public boolean 修改学生(int number) {

boolean flag = false;

try{

for(int i=0;iif(stuInfos[i].getNumber()==number) {

BufferedReader buf = new BufferedReader(new

InputStreamReader(System.in));

StuInfo stu = new StuInfo();

System.out.print(\"\\n请输入学生信息\\n\");

System.out.print(\"姓名:\\n\\n\");

stu.setName(buf.readLine());

System.out.print(\"性别:\\n\\n\");

stu.setSex(buf.readLine());

System.out.print(\"年龄:\\n\\n\");

stu.setAge (buf.readLine());

System.out.print(\"生日:\\n\\n\");

stu.setBir(buf.readLine());

break;

System.out.print(\"邮箱:\\n\\n\");

stu.setEmail(buf.readLine());

System.out.print(\"地址:\\n\\n\");

stu.setAddr(buf.readLine());

System.out.print(\"电话:\\n\\n\");

stu.setTel(buf.readLine());

stu.setNumber(number);

stuInfos[i]=stu;

System.out.print(\"修改完成啦!\");//提示修改完成

}

}

}catch(Exception e){

out.print(e);

}

return flag;

}

public boolean 删除学生(int number){

boolean flag = false;

for(int i=0;iif(stuInfos[i].getNumber()==number){

if(rt==0){

recycle = new StuInfo[101];

}

recycle[rt]=stuInfos[i];

for(;istuInfos[i]=stuInfos[i+1];

}

total--;

flag=true;

break;

}

}

return flag;

}

public void 删除页面(){

System.out.print(\"删除页面\");//请输入要删除的学号

try{

int choice;

BufferedReader buf = new InputStreamReader(System.in));

System.out.println(\"1:学生信息修改\");

System.out.println(\"2:学生信息删除\");

System.out.println(\"请输入您的选择(1--2)\");

//...

choice = Integer.parseInt(buf.readLine());

switch(choice){

case 1:

System.out.println(\"请输入要修改的学号:\");

choice = Integer.parseInt(buf.readLine());

BufferedReader(new

修改学生(choice);

break;

case 2:

System.out.println(\"请输入要删除的学号:\");

choice = Integer.parseInt(buf.readLine());

删除学生(choice);

break;

//补充

}

/*if(删除学生(choice)){

System.out.print(\"删除成功!\");//删除成功

}else{

System.out.print(\"删除失败!\");//删除失败

}*/

}catch(Exception e){

out.print(e);

}

}

public void showMenu() {

try{

int choice;

do{

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(\"0:退出系统\");

System.out.println(\"请输入您的选择(0--6)\");

BufferedReader buf = new InputStreamReader(System.in));

choice = Integer.parseInt(buf.readLine());

switch(choice){

case 1:

信息录入();//

break;

case 2:

//补全方法调用

BufferedReader(new

显示学生(stuInfos, total);

break;

case 3:

查找菜单();

break;

case 4:

删除页面();

break;

case 5:

保存数据();

break;

case 6:

读取数据();

break;

default:

System.out.print(\"出现异常!\"); //异常:7

}

}while(choice!=0);

}catch(Exception e){

System.out.println(e);

}

// TODO 自动生成的方法存根

}

public static void main(String[] args) {

Student student = new Student();

student.showMenu();

}

}

因篇幅问题不能全部显示,请点此查看更多更全内容