JAVA程序设计-宿舍管理系统(完整版)

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

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 show()//显示学生信息的方法

{

System.out.println("学生的学号:" + this.ID);

System.out.println("学生的姓名:" + );

System.out.println("学生的性别:" + this.gender);

System.out.println("学生的房间号:" + this.RoomID);

}

static void showallstudent(ArrayList allarraylist)//创建一个显示所有学生的信息的方法{

for(int i = 0; i

{

System.out.println();

System.out.println("第" + (i + 1) + "名学生:");

Student allstudent = (Student)allarraylist.get(i);

System.out.println("学生的学号:" + allstudent.ID);

System.out.println("学生的姓名:" + );

System.out.println("学生的性别:" + allstudent.gender);

System.out.println("学生的房间号:" + allstudent.RoomID);

System.out.println();

}

}

}

public class Sushe {

public static void main(String[] args)

{

int i = 888;//定义全局变量,并且赋值

ArrayList addarray = new ArrayList();//创建一个动态的存储数组addarray

Room[] room = new Room[5];//创建5个房间

for(int j=0;j

{

room[j] = new Room();

room[j].ID = ("R"+(j+1));

if(j<2)room[j].tpye = "female";

else room[j].tpye = "male";

}

function();

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("请输入姓名:");

localScanner1 = new Scanner(System.in);

= localScanner1.next().toString();

System.out.print("请输入性别:");

localScanner1 = new Scanner(System.in);

localStudent1.gender = localScanner1.next().toString();

for (k = 0; k < room.length; k++)

{

if ((room[k].RN > 0) && (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;

case 2:

System.out.println("所有房间信息如下:");

for (k = 0; k < room.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;

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 (room[m].ID.equals(str1))

{

room[m].show();

break;

}

}

function();

break;

case 4:

Student.showallstudent(addarray);

function();

break;

case 5:

System.out.print("请输入待查询学生的学号:");

Scanner localScanner3 = new Scanner(System.in);

String str2 = localScanner3.next().toString();

相关文档
最新文档