《JAVA程序设计-宿舍管理系统(完整版).docx》由会员分享,可在线阅读,更多相关《JAVA程序设计-宿舍管理系统(完整版).docx(9页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、import java.io.*;import java.util.*;class Room String ID; String tpye; int RN; Room() this.RN = 6; void show() System.out.println(房间的编号:+this.ID); System.out.println(房间的类型:+this.tpye); System.out.println(房间的还能够容纳的学生数量:+this.RN);class Student String name;String ID;String gender;String RoomID;void sho
2、w()/显示学生信息的方法 System.out.println(学生的学号: + this.ID); System.out.println(学生的姓名: + this.name); System.out.println(学生的性别: + this.gender); System.out.println(学生的房间号: + this.RoomID);static void showallstudent(ArrayList allarraylist)/创建一个显示所有学生的信息的方法for(int i = 0; iallarraylist.size();i+) System.out.printl
3、n(); System.out.println(第 + (i + 1) + 名学生:); Student allstudent = (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.printl
4、n();public class Sushe public static void main(String args)int i = 888;/定义全局变量,并且赋值ArrayList addarray = new ArrayList();/创建一个动态的存储数组addarrayRoom room = new Room5;/创建5个房间for(int j=0;jroom.length;j+)/初始化每个房间数roomj = new Room();roomj.ID = (R+(j+1);if(j2)roomj.tpye = female;else roomj.tpye = male;functi
5、on();do/第一个死循环控制总的功能int k;Scanner sc = new Scanner(System.in);i = sc.nextInt(); switch (i) case 1: Student localStudent1 = new Student(); System.out.print(请输入学号:); Scanner localScanner1 = new Scanner(System.in); localStudent1.ID = localScanner1.next().toString(); System.out.print(请输入姓名:); localScann
6、er1 = new Scanner(System.in); localStudent1.name = localScanner1.next().toString(); System.out.print(请输入性别:); localScanner1 = new Scanner(System.in); localStudent1.gender = localScanner1.next().toString(); for (k = 0; k 0) & (roomk.tpye.equals(localStudent1.gender) roomk.RN -= 1; localStudent1.RoomI
7、D = roomk.ID; System.out.println(新添加的学生被分配到房间: + roomk.ID); break; addarray.add(localStudent1); function(); break; case 2: System.out.println(所有房间信息如下:); for (k = 0; k room.length; k+) System.out.println(房间号: + roomk.ID); System.out.println(房间类型: + roomk.tpye); System.out.println(房间还能容纳的学生数: + roomk
8、.RN); System.out.println(); function(); break; case 3: System.out.print(请输入待查询房间的房间号:); Scanner localScanner2 = new Scanner(System.in); String str1 = localScanner2.next().toString(); for (int m = 0; m room.length; m+) if (roomm.ID.equals(str1) roomm.show(); break; function(); break; case 4: Student.
9、showallstudent(addarray); function(); break; case 5: System.out.print(请输入待查询学生的学号:); Scanner localScanner3 = new Scanner(System.in); String str2 = localScanner3.next().toString(); for (int n = 0; n addarray.size(); n+) Student localStudent2 = (Student)addarray.get(n); if (localStudent2.ID.equals(str
10、2) localStudent2.show(); break; function(); break; case 6: System.out.print(请输入待修改学生的学号:); Scanner localScanner5 = new Scanner(System.in); String str5 = localScanner5.next().toString(); for (int i2 = 0; i2 addarray.size(); i2+) Student localStudent3 = (Student)addarray.get(i2); String m = localStude
11、nt3.gender; String m1 = localStudent3.RoomID ; if (localStudent3.ID.equals(str5) System.out.print(请输入修改后的学生的学号:); Scanner localScanner11 = new Scanner(System.in); localStudent3.ID = localScanner11.next().toString(); System.out.print(请输入请输入修改后的学生的姓名:); localScanner11 = new Scanner(System.in); localSt
12、udent3.name = localScanner11.next().toString(); System.out.print(请输入请输入修改后的学生的性别:); localScanner11 = new Scanner(System.in); localStudent3.gender = localScanner11.next().toString(); if (!(m.equals(localStudent3.gender) for(k = 0; k room.length ;k+) if(roomk.ID.equals(m1)roomk.RN+;break; addarray.rem
13、ove(i2); for (k = 0; k 0) & (roomk.tpye.equals(localStudent3.gender) roomk.RN -= 1; localStudent3.RoomID = roomk.ID; System.out.println(修改的学生被分配到房间: + roomk.ID); addarray.add(localStudent3); break; System.out.println(恭喜你!修改成功!); function(); break; case 7: System.out.print(请输入待删除学生的学号:); Scanner loca
14、lScanner4 = new Scanner(System.in); String str3 = localScanner4.next().toString(); for (int i1 = 0; i1 addarray.size(); i1+) Student localStudent3 = (Student)addarray.get(i1); if (localStudent3.ID.equals(str3) System.out.print(学号为 + localStudent3.ID + 的学生已被删除!); addarray.remove(i1); break; function(
15、); break; case 8: showfunction(); break; case 0: System.out.println(tt谢谢使用!ntt(*_*)ntt再见!); break; default: System.out.println(你按的神马东西,没看说明吗?tt-_-#); function();while(i!=0);static void function() System.out.println(*); System.out.println(*tt宿舍管理系统); System.out.println(*); System.out.println(*t1 新增学生
16、、并分配宿舍); System.out.println(*); System.out.println(*t2 查看宿舍信息); System.out.println(*); System.out.println(*t3 按房间号查看房间信息); System.out.println(*); System.out.println(*t4 查看所有学生信息); System.out.println(*); System.out.println(*t5 按学生学号查询学生信息); System.out.println(*); System.out.println(*t6 按学号修改学生信息); Sy
17、stem.out.println(*); System.out.println(*t7 删除指定学生); System.out.println(*); System.out.println(*t8 !详细使用说明信息!); System.out.println(*); System.out.println(*t0 退出);System.out.println(*); System.out.println(Please select a funtion:);static void showfunction() System.out.println(*); System.out.println(|
18、ttJAVA程序设计 ); System.out.println(|tt ); System.out.println(|tt作者:李月超 ); System.out.println(|tt ); System.out.println(|tt班级:乐山师范学院_计科学院_12级网络工程班); System.out.println(|tt ); System.out.println(|tt开发日期:2013年12月);System.out.println(*);System.out.println(*课程题目:n*设计宿舍管理系统n*宿舍管理要求:n*可以新增学生,新增学生的同时,按以上要求由系统
19、自动将学生安排进房间n*可以列出所有房间信息n*可以通过房间号查看房间信息,以及该房间内住宿学生的信息n*可以列出所有学生信息n*可以通过学生学号查看学生的信息n*可以删除指定学生);System.out.println(*tt提示:n*此程序的功能只能是0-9数字输入n*性别只能是female或者是male!);System.out.println(-);System.out.println(|tt宿舍管理系统); System.out.println(|t1 新增学生、并分配宿舍); System.out.println(|t2 查看宿舍信息); System.out.println(|t3 按房间号查看房间信息); System.out.println(|t4 查看所有学生信息); System.out.println(|t5 按学生学号查询学生信息); System.out.println(|t6 按学号修改学生信息); System.out.println(|t7 删除指定学生); System.out.println(|t8 !详细使用说明信息!); System.out.println(|t0 退出);System.out.println(-); System.out.println(Please select a funtion:);
限制150内