您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > JAVA程序设计-宿舍管理系统(完整版)
importjava.io.*;importjava.util.*;classRoom{StringID;Stringtpye;intRN;Room(){this.RN=6;}voidshow(){System.out.println(房间的编号:+this.ID);System.out.println(房间的类型:+this.tpye);System.out.println(房间的还能够容纳的学生数量:+this.RN);}}classStudent{Stringname;StringID;Stringgender;StringRoomID;voidshow()//显示学生信息的方法{System.out.println(学生的学号:+this.ID);System.out.println(学生的姓名:+this.name);System.out.println(学生的性别:+this.gender);System.out.println(学生的房间号:+this.RoomID);}staticvoidshowallstudent(ArrayListallarraylist)//创建一个显示所有学生的信息的方法{for(inti=0;iallarraylist.size();i++){System.out.println();System.out.println(第+(i+1)+名学生:);Studentallstudent=(Student)allarraylist.get(i);System.out.println(学生的学号:+allstudent.ID);System.out.println(学生的姓名:+allstudent.name);System.out.println(学生的性别:+allstudent.gender);System.out.println(学生的房间号:+allstudent.RoomID);System.out.println();}}}publicclassSushe{publicstaticvoidmain(String[]args){inti=888;//定义全局变量,并且赋值ArrayListaddarray=newArrayList();//创建一个动态的存储数组addarrayRoom[]room=newRoom[5];//创建5个房间for(intj=0;jroom.length;j++)//初始化每个房间数{room[j]=newRoom();room[j].ID=(R+(j+1));if(j2)room[j].tpye=female;elseroom[j].tpye=male;}function();do//第一个死循环控制总的功能{intk;Scannersc=newScanner(System.in);i=sc.nextInt();switch(i){case1:StudentlocalStudent1=newStudent();System.out.print(请输入学号:);ScannerlocalScanner1=newScanner(System.in);localStudent1.ID=localScanner1.next().toString();System.out.print(请输入姓名:);localScanner1=newScanner(System.in);localStudent1.name=localScanner1.next().toString();System.out.print(请输入性别:);localScanner1=newScanner(System.in);localStudent1.gender=localScanner1.next().toString();for(k=0;kroom.length;k++){if((room[k].RN0)&&(room[k].tpye.equals(localStudent1.gender))){room[k].RN-=1;localStudent1.RoomID=room[k].ID;System.out.println(新添加的学生被分配到房间:+room[k].ID);break;}}addarray.add(localStudent1);function();break;case2:System.out.println(所有房间信息如下:);for(k=0;kroom.length;k++){System.out.println(房间号:+room[k].ID);System.out.println(房间类型:+room[k].tpye);System.out.println(房间还能容纳的学生数:+room[k].RN);System.out.println();}function();break;case3:System.out.print(请输入待查询房间的房间号:);ScannerlocalScanner2=newScanner(System.in);Stringstr1=localScanner2.next().toString();for(intm=0;mroom.length;m++){if(room[m].ID.equals(str1)){room[m].show();break;}}function();break;case4:Student.showallstudent(addarray);function();break;case5:System.out.print(请输入待查询学生的学号:);ScannerlocalScanner3=newScanner(System.in);Stringstr2=localScanner3.next().toString();for(intn=0;naddarray.size();n++){StudentlocalStudent2=(Student)addarray.get(n);if(localStudent2.ID.equals(str2)){localStudent2.show();break;}}function();break;case6:System.out.print(请输入待修改学生的学号:);ScannerlocalScanner5=newScanner(System.in);Stringstr5=localScanner5.next().toString();for(inti2=0;i2addarray.size();i2++){StudentlocalStudent3=(Student)addarray.get(i2);Stringm=localStudent3.gender;Stringm1=localStudent3.RoomID;if(localStudent3.ID.equals(str5)){System.out.print(请输入修改后的学生的学号:);ScannerlocalScanner11=newScanner(System.in);localStudent3.ID=localScanner11.next().toString();System.out.print(请输入请输入修改后的学生的姓名:);localScanner11=newScanner(System.in);localStudent3.name=localScanner11.next().toString();System.out.print(请输入请输入修改后的学生的性别:);localScanner11=newScanner(System.in);localStudent3.gender=localScanner11.next().toString();if(!(m.equals(localStudent3.gender))){for(k=0;kroom.length;k++){if(room[k].ID.equals(m1)){room[k].RN++;break;}}addarray.remove(i2);for(k=0;kroom.length;k++){if((room[k].RN0)&&(room[k].tpye.equals(localStudent3.gender))){room[k].RN-=1;localStudent3.RoomID=room[k].ID;System.out.println(修改的学生被分配到房间:+room[k].ID);addarray.add(localStudent3);break;}}}System.out.println(恭喜你!修改成功!);function();}}break;case7:System.out.print(请输入待删除学生的学号:);ScannerlocalScanner4=newScanner(System.in);Stringstr3=localScanner4.next().toString();for(inti1=0;i1addarray.size();i1++){StudentlocalStudent3=(Student)addarray.get(i1);if(localStudent3.ID.equals(str3)){System.out.print(学号为+localStudent3.ID+的学生已被删除!);addarray.remove(i1);break;}}function();break;case8:showfunction();break;case0:System.out.println(\t\t谢谢使用!\n\t\t(*^__^*)\n\t\t再见!);break;default:System.out.println(你按的神马东西,没看说明吗?\t\t-_-#);function();}}while(i!=0);}staticvoidfunction(){System.out.println(***************************************);System.out.println(*\t\t宿舍管理系统);System.out.println(*);System.out.println(*\t[1]新增学生、并分配宿舍);System.out.println(*);System.out.println(*\t[2]查看宿舍信息);System.out.println(*);System.out.println(*\t[3]按房间号查看房间信息);System.out.println(*);System.out.println(*\t[4]查看所有学生信息);System.out.println(*);System.out.println(*\t[5]按学生学号查询学生信息);System.out.println(*);System.out.println(*\t[6]按学号修改学生信息);System.out.println(*);System.out.println(*\t[7]删除指定学生);System.out.println(*);System.out.println(*\t[8]!!!详细使用说明信息!!!);System.out.println(*);System.out.println(*\t[0]退出);System.out.println(***************************************);System.out.println(Pleaseselectafuntion:);}staticvoidshowfunction(){System.out.println(****************
本文标题:JAVA程序设计-宿舍管理系统(完整版)
链接地址:https://www.777doc.com/doc-7339439 .html