首页 > 作文

java实现学生宿舍系统

更新时间:2023-04-06 04:17:53 阅读: 评论:0

本文实例为大家分享了java实现学生宿舍管理系统的具体代码,供大家参考,具体内容如下

学生类代码

student.java

package dormitory;public class student {  private string id;  private string name;  private string x;  private string dormid;  public string getid() {    return id;  }  public void tid(string id) {    this.id = id;  }  public string getname() {    return name;  }  public void tname(string name) {    this.name = name;  }  public string getx() {    return x;  }  public void tx(string x) {    this.x = x;  }  public string getdormid() {    return dormid;  }  public void tdormid(string dormid) {    this.dormid = dormid;  }}

主操作代码

intailstudent.java

package dormitory;import java.awt.list;import java.io.bufferedreader;import java.io.bufferedwriter;import java.io.filenotfoundexception;import java.io.filereader;import java.io.filewriter;import java.io.ioexception;import java.util.arraylist;import java.util.iterator;import java.util.scanner;import javax.print.docflavor.input_stream;import javax.swing.event.listlectionevent;import org.omg.portableinterceptor.iorinterceptor;public class initailstudent {  private static int n=0;  private static student[] stu=new student[100];  //主函数  public static void main(string[] args) throws ioexception {    boolean a=fal;    boolean b=fal;    initailstudent student=new initailstudent();    student.judge(a, b);  }  //登入函数  private void judge(boolean a, boolean b) throws ioexception  {    do {      system.out.println("欢迎进入登入页面!");      scanner input=new scanner(system.in);      system.out.println("请输入账号:");      string account=input.nextline();      system.out.println("请输入密码:");      string code=input.nextline();      a=account.equals("admin");      b=code.equals("admin");    } while(!(a==true&&b==true));    menu();  }  //系统菜单页面  private void menu() throws ioexception{    scanner input=new scanner(system.in);    system.out.println("------ 欢迎进入宿舍管理系统 ------");    system.out.println("------ 请选择下列操作       ------");    system.out.println("---   1.显示所有学生信息     ---");   //show()    system.out.println("---   2.查询学生信息         ---");   //find()    system.out.println("---   3.增加学生信息         ---");   //add()    system.out.println("---   4.修改学生信息         ---");   //renew()    system.out.println("---   5.删除学生信息         ---");   //delete()    system.out.println("---   0.退出系统             ---");    system.out.println("请输入1~5:");    int a=input.nextint();    while(a<0||a>5)    {      system.out.println("输入有误,请重新输入:");      a=input.nextint();    }    switch (a) {    ca 1:      show();      break;    ca 2:      find();      break;    ca 3:      add();      break;    ca 4:      renew();      break;    ca 5:      delete();      break;    ca 0:      system.out.println("成功退出系统!");      system.exit(0);      break;    }  }  //显示学生的全部信息  private void show() throws ioexception{    system.out.println("您总录入的信息如下:");    system.out.println("*****************************");    bufferedreader br=new bufferedreader(new filereader("student.txt"));    string line;    while((line=br.readline())!=null){      system.out.println(line);    }    br.clo();    system.out.println("\n\r");    system.out.println("此次录入的信息为");    system.out.println("*****************************");    int i;    for(i=0;i<n;i++)    {      system.out.println("学号:"+stu[i].getid()+"\t姓名:"+stu[i].getname()+"\t性别:"+stu[i].getx()+"\t宿舍号:"+stu[i].getdormid());    }    system.out.println("返回主菜单");    menu();  }  //查询学生信息  private void find() throws ioexception{    arraylist<arraylist<string>> lists = new arraylist<>();    bufferedreader br=new bufferedreader(new filereader("student.txt"));    string line;    arraylist<string> list = new arraylist<>();    arraylist<string> validlist = new arraylist<>();    while((line=br.readline())!=null){      list.add(line.tostring());    }    br.clo();    for(int i = 0;i<list.size();i++)      if(i!=0&&list.get(i-1).startswith("学号")){        validlist.add(list.get(i));    }    for (string string : validlist) {      string[] split = string.split("   ");      arraylist<string> tempstring = new arraylist<>();      for (string string2 : split) {        tempstring.add(string2);      }      lists.add(tempstring);    }     system.out.println("共有"+lists.size()+"个学生信息");    string[][] stu1=new string[lists.size()][4];    for(int i=0;i<lists.size();i++)      for(int j=0;j<4;j++){        stu1[i][j]=lists.get(i).get(j);      }    s小小讲解员ystem.out.println("请输入学生的学号:");    scanner input=new scanner(system.in);    string d=input.next();    for(int i=0;i<stu1.length;i++)    {      if(d.equals(stu1[i][0]))      {        system.out.println("查询成功,以下为该学生的信息");        system.out.println("学号:"+stu1[i][0]+"\t姓名:"+stu1[i][1]+"\t性别:"+stu1[i][2]+"\t宿舍号:"+stu1[i][3]);        system.out.println("是否继续查询,否返回菜单,是y否n");        string cho=input.next();        char ch=cho.charat(0);        while(ch!='y'&am解释造句p;&ch!='y'&&ch!='n'&&ch!='n')        {          system.out.println("输入有误!请重新输入:");          cho=input.next();          ch=cho.charat(0);        }        while(ch=='y'||ch=='y'){          find();        }        while(ch=='n'||ch=='n'){          menu();        }      }    }    system.out.println("没有找到该学生,是继续输入,否返回菜单,是y否n");    string cho=input.next();    char ch=cho.charat(0);    while(ch!='y'&&ch!='y'&&ch!='n'&&ch!='n')    {      system.out.println("输入有误!请重新输入:");      cho=input.next();      ch=cho.charat(0);    }    while(ch=='y'||ch=='y'){      find();    }    while(ch=='n'||ch=='n'){      menu();    }  }  //增加一个学生  private void add() throws ioexception{    string id;    string dormid;    string name;    string x;    string cho;    char ch;    stu[n]=new student();    scanner input=new scanner(system.in);    if(n==0)    {      system.out.println("您此次还没有录入任何信息,是否录入,是y否n");      cho=input.next();      ch=cho.charat(0);      while(ch!='y'&&ch!='y'&&ch!='n'&&ch!='n')      {        system.out.println("输入有误!请重新输入:");        cho=input.next();        ch=cho.charat(0);      }      while(ch=='y'||ch=='y'){        break;      }      while(ch=='n'||ch=='n'){        menu();      }    }    filewriter fw=new filewriter("student.txt",true);    fw.write("\r\n");    fw.write("学号    姓名   性别   宿舍号 \r\n");    system.out.println("请输入学生的学号:");    id=input.next();    stu[n].tid(id);    fw.write(stu[n].getid()+"    ");    system.out.println("请输入学生的姓名:");    name=input.next();    stu[n].tname(name);    fw.write(stu[n].getname()+"   ");    system.out.println("请输入学生的性别:");    x=input.next();    stu[n].tx(x);    fw.write(stu[n].getx()+"   ");    system.out.println("请输入学生的宿舍号:");    dormid=input.next();    stu[n].tdormid(dormid);    fw.write(stu[n].getdormid()+"    ");    n++;    fw.clo();    system.out.println("是否继续添加学生?否返回主菜单,是y否n");    cho=input.next();    ch=cho.charat(0);    while(ch!='y'&&ch!='y'&&ch!='n'&&ch!='n')    {      system.out.println("输入有误!请重新输入:");      cho=input.next();      ch=cho.charat(0);    }    while(ch=='y'||ch=='y'){      add();    }    while(ch=='n'||ch=='n'){      menu();    }  }  //修改学生信息  private void renew() throws ioexception{    arraylist<arraylist<string>> lists = new arraylist<>();    bufferedreader br=new bufferedreader(new filereader("student.txt"));    string line;    arraylist<string> list = new arraylist<>();    arraylist<string> validlist = new arraylist<>();    while((line=br.readline())!=null){      list.add(line.tostring());    }    br.clo();    for(int i = 0;i<list.size();i++)      if(i!=0&&list.get(i-1).startswith("学号")){        validlist.add(list.get(i));    }    for (string string : validlist) {      string[] split = string.split("   ");      arraylist<string> tempstring = new arraylist<>();      for (string string2 : split) {        tempstring.add(string2);      }      lists.add(tempstring);    }     string[][] stu1=new string[lists.size()][4];    for(int i=0;i<lists.size();i++)      for(int j=0;j<4;j++){        stu1[i][j]=lists.get(i).get(j);      }    int temp=0;    boolean flag=fal;    system.out.println("请输入要修改学生的学号:");    scanner input=new scanner(system.in);    string d=input.next();    for(int i=0;i<stu1.length;i++)    {      while(d.equals(stu1[i][0]))      {        temp=i;        flag=true;        break;      }    }    if(!flag)    {      system.out.println("输入的学号有误,未找到该学生,是否再次进入修改,是y,否n");      string cho1=input.next();      char ch1=cho1.charat(0);      while (ch1!='n'&&ch1!='n'&&ch1!='y'&&ch1!='y')      {        system.out.print谭咏麟百科ln("输入无效,请重新输入:");        cho1=input.next();        ch1=cho1.charat(0);      }      if (ch1=='y'||ch1=='y'){        renew();      }      if (ch1=='n'||ch1=='n'){        system.out.println("返回主菜单");        menu();      }    }    el    {      system.out.println("您要修改的学生的信息如下:");      system.out.println("学号:"+stu1[temp][0]+"\t姓名:"+stu1[temp][1]+"\t性别:"+stu1[temp][2]+"\t宿舍号:"+stu1[temp][3]);      system.out.println("请以下选择要修改的内容:");      system.out.println("------  1.姓名    ------");      system.out.println("------  2.性别    ------");      system.out.println("------  3.宿舍号   ------");      scanner input1=new scanner(system.in);      int a=input1.nextint();      if(a==1)      {        system.out.println("请输入新的姓名:");        string name=input1.next();        stu1[temp][1]=name;        filewriter fw1=new filewriter("student.txt");        fw1.write("   ");        fw1.clo();        filewriter fw=new filewriter("student.txt",true);        fw.write("\r\n"+"      "+"学生信息表\r\n");        for(int i=0;i<stu1.length;i++)        {          fw.write("\r\n学号    姓名   性别   宿舍号 \r\n");          fw.write(stu1[i][0]+"    ");          fw.write(stu1[i][1]+"    ");          fw.write(stu1[i][2]+"    ");          fw.write(stu1[i][3]+"    ");        }        fw.clo();        system.out.println("修改成功!");        system.out.println("还要继续修改吗?是继续修改,否返回主菜单,是y否n");        string cho1=input1.next();        char ch1=cho1.charat(0);        while (ch1!='n'&&ch1!='n'&&ch1!='y'&&ch1!='y')        {          system.out.println("输入无效,请重新输入:");          cho1=input.next();          ch1=cho1.charat(0);        }        if (ch1=='y'||ch1=='y'){          renew();        }        if (ch1=='n'||ch1=='n'){          system.out.println("返回主菜单");          menu();        }      }      el if(a==2)      {        system.out.println("请输入新的性别:");        string x=input1.next();        stu1[temp][2]=x;        filewriter fw1=new filewriter("student.txt");        fw1.write("   ");        fw1.clo();        filewriter fw=new filewriter("student.txt",true);        fw.write("\r\n"+"      "+"学生信息表\r\n");        for(int i=0;i<stu1.length;i++)        {          fw.write("\r\n学号    姓名   性别   宿舍号 \r\n");          fw.write(stu1[i][0]+"    ");          fw.write(stu1[i][1]+"    ");          fw.wr列数字的作用ite(stu1[i][2]+"    ");          fw.write(stu1[i][3]+"    ");        }        fw.clo();        system.out.println("修改成功!");        system.out.println("还要继续修改吗?是继续修改,否返回主菜单,是y否n");        string cho1=input1.next();        char ch1=cho1.charat(0);        while (ch1!='n'&&ch1!='n'&&ch1!='y'&&ch1!='y')        {          system.out.println("输入无效,请重新输入:");          cho1=input.next();          ch1=cho1.charat(0);        }        if (ch1=='y'||ch1=='y'){          renew();        }        if (ch1=='n'||ch1=='n'){          system.out.println("返回主菜单");          menu();        }      }      el if(a==3)      {        system.out.println("请输入新的宿舍号:");        string dormid=input1.next();        stu1[temp][3]=dormid;        filewriter fw1=new filewriter("student.txt");        fw1.write("   ");        fw1.clo();        filewriter fw=new filewriter("student.txt",true);        fw.write("\r\n"+"      "+"学生信息表\r\n");        for(int i=0;i<stu1.length;i++)        {          fw.write("\r\n学号    姓名   性别   宿舍号 \r\n");          fw.write(stu1[i][0]+"    ");          fw.write(stu1[i][1]+"    ");          fw.write(stu1[i][2]+"    ");          fw.write(stu1[i][3]+"    ");        }        fw.clo();        system.out.println("修改成功!");        system.out.println("还要继续修改吗?是继续修改,否返回主菜单,是y否n");        string cho1=input1.next();        char ch1=cho1.charat(0);        while (ch1!='n'&&ch1!='n'&&ch1!='y'&&ch1!='y')        {          system.out.println("输入无效,请重新输入:");          cho1=input.next();          ch1=cho1.charat(0);        }        if (ch1=='y'||ch1=='y'){          renew();        }        if (ch1=='n'||ch1=='n'){          system.out.println("返回主菜单");          menu();        }      }      el {        system.out.println("输入有误,请重新输入:");        renew();      }    }  }  //删除学生信息  private void delete() throws ioexception{    arraylist<arraylist<string>> lists = new arraylist<>();    bufferedreader br=new bufferedreader(new filereader("student.txt"));    string line;    arraylist<string> list = new arraylist<>();    arraylist<string> validlist = new arraylist<>();    while((line=br.readline())!=null){      list.add(line.tostring());    }    br.clo();    for(int i = 0;i<list.size();i++)      if(i!=0&&list.get(i-1).startswith("学号")){        validlist.add(list.get(i));    }    for (string string : validlist) {      string[] split = string.split("   ");      arraylist<string> tempstring = new arraylist<>();      for (string string2 : split) {        tempstring.add(string2);      }      lists.add(tempstring);    }    string[][] stu1=new string[lists.size()][4];    for(int i=0;i<lists.size();i++)      for(int j=0;j<4;j++){        stu1[i][j]=lists.get(i).get(j);      }    int temp=0;    boolean flag=true;    system.out.println("请输入你想要删除该学生的学号:");    scanner input2=new scanner(system.in);    string d=input2.next();    for(int i=0;i<stu1.length;i++)    {      while(d.equals(stu1[i][0]))      {        temp=i;        flag=true;        break;      }    }    if(!flag)    {      system.out.println("输入的学号有误,未找到该学生,再次进入删除,请重新输入:");      string cho1=input2.next();      char ch1=cho1.charat(0);      while (ch1!='n'&&ch1!='n'&&ch1!='y'&&ch1!='y')      {        system.out.println("输入无效,请重新输入:");        cho1=input2.next();        ch1=cho1.charat(0);      }      if (ch1=='y'||ch1=='y'){        delete();      }      if (ch1=='n'||ch1=='n'){        system.out.println("返回主菜单");        menu();      }    }    el{      system.out.println("您要删除的学生的信息如下:");      system.out.println("学号:"+stu1[temp][0]+"\t姓名:"+stu1[temp][1]+"\t性别:"+stu1[temp][2]+"\t宿舍号:"+stu1[temp][3]);      for (int i=temp;i<stu1.length-1;i++)      {        stu1[i]=stu1[i+1];      }      filewriter fw1=new filewriter("student.txt");      fw1.write("   ");      fw1.clo();      filewriter fw=new filewriter("student.txt",true);      fw.write("\r\n"+"      "+"学生信息表\r\n");      for(int i=0;i<stu1.length-1;i++)      {        fw.write("\r\n学号    姓名   性别   宿舍号 \r\n");        fw.write(stu1[i][0]+"    ");        fw.write(stu1[i][1]+"    ");        fw.write(stu1[i][2]+"    ");        fw.write(stu1[i][3]+"    ");      }      fw.clo();       system.out.println("删除该学生信息成功!");      system.out.println("---------------------");    }    system.out.println("还要继续删除吗?是继续删除,否返回主菜单,是y否n");    string cho2=input2.next();    char ch2=cho2.charat(0);    while (ch2!='n'&&ch2!='n'&&ch2!='y'&&ch2!='y')    {      system.out.println("输入无效,请重新输入:");      cho2=input2.next();      ch2=cho2.charat(0);    }    if (ch2=='y'||ch2=='y'){拮据的反义词      delete();    }    if (ch2=='n'||ch2=='n'){      system.out.println("返回主菜单");      menu();    }  }}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持www.887551.com。

本文发布于:2023-04-06 04:17:51,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/f6134959b537c8b1bf7c5c31a6a3c480.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:java实现学生宿舍系统.doc

本文 PDF 下载地址:java实现学生宿舍系统.pdf

下一篇:返回列表
标签:学号   学生   主菜   请输入
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图