欢迎来到天天文库
浏览记录
ID:47527858
大小:90.01 KB
页数:12页
时间:2020-01-13
《JAVA程序设计-宿舍管理系统(完整版)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、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
2、;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(i
3、nti=0;i4、nder);System.out.println("学生的房间号:"+allstudent.RoomID);System.out.println();}}}publicclassSushe{publicstaticvoidmain(String[]args){inti=888;//定义全局变量,并且赋值ArrayListaddarray=newArrayList();//创建一个动态的存储数组addarrayRoom[]room=newRoom[5];//创建5个房间for(intj=0;j5、初始化每个房间数{room[j]=newRoom();room[j].ID=("R"+(j+1));if(j<2)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("请输入学号:");Scanne6、rlocalScanner1=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);loca7、lStudent1.gender=localScanner1.next().toString();for(k=0;k0)&&(room[k].tpye.equals(localStudent1.gender))){room[k].RN-=1;localStudent1.RoomID=room[k].ID;System.out.println("新添加的学生被分配到房间:"+room[k].ID);break;}}addarray.add(localStudent18、);function();break;case2:System.out.println("所有房间信息如下:");for(k=0;k
4、nder);System.out.println("学生的房间号:"+allstudent.RoomID);System.out.println();}}}publicclassSushe{publicstaticvoidmain(String[]args){inti=888;//定义全局变量,并且赋值ArrayListaddarray=newArrayList();//创建一个动态的存储数组addarrayRoom[]room=newRoom[5];//创建5个房间for(intj=0;j5、初始化每个房间数{room[j]=newRoom();room[j].ID=("R"+(j+1));if(j<2)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("请输入学号:");Scanne6、rlocalScanner1=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);loca7、lStudent1.gender=localScanner1.next().toString();for(k=0;k0)&&(room[k].tpye.equals(localStudent1.gender))){room[k].RN-=1;localStudent1.RoomID=room[k].ID;System.out.println("新添加的学生被分配到房间:"+room[k].ID);break;}}addarray.add(localStudent18、);function();break;case2:System.out.println("所有房间信息如下:");for(k=0;k
5、初始化每个房间数{room[j]=newRoom();room[j].ID=("R"+(j+1));if(j<2)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("请输入学号:");Scanne
6、rlocalScanner1=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);loca
7、lStudent1.gender=localScanner1.next().toString();for(k=0;k0)&&(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
8、);function();break;case2:System.out.println("所有房间信息如下:");for(k=0;k
此文档下载收益归作者所有