2021 级软工JAVA课堂测试试卷(一)宿舍管理系统
package student;
public class RoomInformation {
String roomno;
String roomno1;
String roomno2;
String roomno3;
String roomno4;
int hygienescore;
public String getroomno() {
return roomno;
}
public void setroomno(String roomno) {
this.roomno = roomno;
}
public String getroomno1() {
return roomno1;
}
public void setroomno1(String roomno1) {
this.roomno1 = roomno1;
}
public String getroomno2() {
return roomno2;
}
public void setroomno2(String roomno2) {
this.roomno2 = roomno2;
}
public String roomno3() {
return roomno3;
}
public void setroomno3(String roomno3) {
this.roomno3 = roomno3;
}
public String getroomno4() {
return roomno4;
}
public void setroomno4(String roomno4) {
this.roomno4 = roomno4;
}
public int gethygienescore() {
return hygienescore;
}
public void sethygienescore(int hygienescore) {
this.hygienescore = hygienescore;
}
RoomInformation(String roomno,String roomno1,String roomno2,String roomno3,String roomno4,int hygienescore)
{
this.roomno = roomno;
this.roomno1 = roomno1;
this.roomno2 = roomno2;
this.roomno3 = roomno3;
this.roomno4 = roomno4;
this.hygienescore=hygienescore;
}
}
package student;
import java.util.Scanner;
public class RoomManagement {
static int sum=10;
static int sex[]= {1,1,1,1,1,1,1,1,1,1};
static Scanner s;
static RoomInformation a[] = new RoomInformation[10];
static int d[]= {0,0,0,0,0,0,0,0,0,0};
public static void systemMenu() {
System.out.println("*************************************************************** \n" +
" -------石家庄铁道大学 \n" +
" 学生公寓管理系统 v2022 \n" +
"**************************************************************** \n" +
" 1、 宿舍查询; \n" +
" 2、 安排新宿舍; \n" +
" 3、 调整宿舍; \n" +
" 4、 宿舍卫生评价; \n" +
" 5、 卫生检查情况查询; \n" +
"****************************************************************");
}
public static void panduan(String a1,String a2,String a3,String a4) {
String b[]= {a1,a2,a3,a4};
int you=0;
int bn=4;
for(int i=0;i<4;i++) {
if(b[i]!=null) {
you++;
}
}
int kong=bn-you;
if(kong==0) {
System.out.println("4人 "+"已满 \n");
}
else if(kong==4) {
System.out.println("0人 "+"空宿舍 \n");
}
else {
System.out.println(you+"人 "+"空"+kong+"人 \n");
}
}
public static void chaxun() {
int i=0;
System.out.println("*************************************************************** \n" +
" -------石家庄铁道大学 \n" +
" 学生公寓管理系统 v2022 \n" +
"**************************************************************** \n" +
" 宿舍详细信息列表 \n"
);
for(i=0;i<sum;i++) {
System.out.print(i+1+"."+a[i].roomno+" ");
panduan(a[i].roomno1,a[i].roomno2,a[i].roomno3,a[i].roomno4);
}
System.out.println("*************************************************************** \n");
}
//用于判断输入学号是否重复
public static void pabduan1(String a) {
}
public static void anpai() {
int num=1;
System.out.println("*************************************************************** \n" +
" -------石家庄铁道大学 \n" +
" 学生公寓管理系统 v2022 \n" +
"**************************************************************** \n" +
" 宿舍详细信息列表 \n"
);
for(int j=0;j<sum;j++) {
String b[]= {a[j].roomno1,a[j].roomno2,a[j].roomno3,a[j].roomno4};
int you=0;
int bn=4;
int i=0;
for(i=0;i<4;i++) {
if(b[i]!=null) {
you++;
}
}
int kong=bn-you;
if(kong==4) {
System.out.print(num+".");
System.out.println(a[j].roomno+" "+"0人 "+"空宿舍 \n");
num++;
} }
System.out.println("*************************************************************** \n");
int ding = 0;
var sc=new Scanner(System.in);
String shuru=sc.next();
for(int j=0;j<sum;j++) {
if(shuru.equals(a[j].roomno)) {
ding=j;
}
}
String b[]= {a[ding].roomno1,a[ding].roomno2,a[ding].roomno3,a[ding].roomno4};
int renshu=0;
for(int n=0;n<4;n++) {
if(b[n]!=null) {
renshu++;
}
}
if(renshu>0) {
System.out.println("该宿舍不是空宿舍,无法安排新生");
return;
}
else
{
System.out.println("输入宿舍号正确");
}
System.out.println("请继续输入新宿舍各床位学号");
var sr=new Scanner(System.in);
String a1=sr.next();
for(int i=0;i<sum;i++) {
String b1[]= {a[i].roomno1,a[i].roomno2,a[i].roomno3,a[i].roomno4};
for(int j=0;j<4;j++) {
if(a1.equals(b1[j])) {
System.out.println("该学生已分配宿舍");
return;
}
else if(a1.equals("END")) {
return;
}
else {}
}
}
a[ding].setroomno1(a1);
String a2=sr.next();
for(int i=0;i<sum;i++) {
String b2[]= {a[i].roomno1,a[i].roomno2,a[i].roomno3,a[i].roomno4};
for(int j=0;j<4;j++) {
if(a2.equals(b2[j])) {
System.out.println("该学生已分配宿舍");
return;
}
else if(a2.equals("END")) {
return;
}
else {}
}
}
a[ding].setroomno2(a2);
String a3=sr.next();
for(int i=0;i<sum;i++) {
String b3[]= {a[i].roomno1,a[i].roomno2,a[i].roomno3,a[i].roomno4};
for(int j=0;j<4;j++) {
if(a3.equals(b3[j])) {
System.out.println("该学生已分配宿舍");
return;
}
else if(a3.equals("END")) {
return;
}
else {}
}
}
a[ding].setroomno3(a3);
String a4=sr.next();
for(int i=0;i<sum;i++) {
String b4[]= {a[i].roomno1,a[i].roomno2,a[i].roomno3,a[i].roomno4};
for(int j=0;j<4;j++) {
if(a4.equals(b4[j])) {
System.out.println("该学生已分配宿舍");
return;
}
else if(a4.equals("END")) {
return;
}
else {}
}
}
a[ding].setroomno4(a4);
String d[]= {a[ding].roomno1,a[ding].roomno2,a[ding].roomno3,a[ding].roomno4};
int renshu1=4;
for(int n=0;n<4;n++) {
if(b[n]!=null) {
renshu1--;
}
}
System.out.println("*************************************************************** \n" +
" 石家庄铁道大学 \n" +
" 学生公寓管理系统 v2022 \n" +
" 安排新宿舍\n"+
"**************************************************************** \n" +
" 新宿舍号: \n" +
" 1、床位1:" +a[ding].roomno1 +"\n"+
" 2、床位2:" + a[ding].roomno2+"\n"+
" 3、床位3:" + a[ding].roomno3+"\n"+
" 4、床位4:" + a[ding].roomno4+"\n"+
"****************************************************************");
if(renshu1==4) {
System.out.println("提示该宿舍已满");
}
}
public static void tiaozheng() {
int num=1;
System.out.println("*************************************************************** \n" +
" -------石家庄铁道大学 \n" +
" 学生公寓管理系统 v2022 \n" +
"**************************************************************** \n" +
" 有空位宿舍详细信息列表 \n"
);
for(int j=0;j<sum;j++) {
String b[]= {a[j].roomno1,a[j].roomno2,a[j].roomno3,a[j].roomno4};
int you=0;
int bn=4;
int i=0;
for(i=0;i<4;i++) {
if(b[i]!=null) {
you++;
}
}
int kong=bn-you;
if(kong==4) {
System.out.print(num+".");
System.out.println(a[j].roomno+" "+"0人 "+"空宿舍 \n");
num++;
}
else if(kong>0&&kong<4) {
System.out.print(num+".");
System.out.println(a[j].roomno+" "+you+"人 "+"空"+kong+"人\n");
num++;
}
}
System.out.println("请输入待调整宿舍号");
System.out.println("*************************************************************** \n");
int ding=0;
System.out.println("请输入调整的宿舍号");
var sc=new Scanner(System.in);
String shuru=sc.next();
int ding1=0;
for(int j=0;j<sum;j++) {
if(shuru.equals(a[j].roomno)) {
ding1=j;
}
}
String b[]= {a[ding1].roomno1,a[ding1].roomno2,a[ding1].roomno3,a[ding1].roomno4};
int renshu=0;
for(int n=0;n<4;n++) {
if(b[n]!=null) {
renshu++;
}
}
if(renshu==4) {
System.out.print("该宿舍没有空床位,无法调整");
return;
}
else
{
System.out.println("输入宿舍号正确");
}
System.out.println("*************************************************************** \n" +
" 石家庄铁道大学 \n" +
" 学生公寓管理系统 v2022 \n" +
" 调整宿舍\n"+
"**************************************************************** \n" +
" 待调整宿舍号:"+a[ding1].roomno+"\n"+
" 1、床位1:" +a[ding1].roomno1 +"\n"+
" 2、床位2:" + a[ding1].roomno2+"\n"+
" 3、床位3:" + a[ding1].roomno3+"\n"+
" 4、床位4:" + a[ding1].roomno4+"\n"+
"****************************************************************");
System.out.print("请输入空床位信息");
String c[]= {a[ding1].roomno1,a[ding1].roomno2,a[ding1].roomno3,a[ding1].roomno4};
int dingdian=0;
for(int n=0;n<4;n++) {
if(c[n]==null) {
dingdian=n;
}
}
var ru=new Scanner(System.in);
String shuru1=ru.next();
for(int i=0;i<sum;i++) {
String b4[]= {a[i].roomno1,a[i].roomno2,a[i].roomno3,a[i].roomno4};
for(int j=0;j<4;j++) {
if(shuru1.equals(b4[j])) {
System.out.println("该学生已分配宿舍");
return;
}
else if(shuru1.equals("END")) {
return;
}
else {}
}
}
if(dingdian==1) {
a[ding1].roomno1=shuru1;
}
else if(dingdian==2) {
a[ding1].roomno2=shuru1;
}
else if(dingdian==3) {
a[ding1].roomno3=shuru1;
}
else {
a[ding1].roomno4=shuru1;
}
String g[]= {a[ding1].roomno1,a[ding1].roomno2,a[ding1].roomno3,a[ding1].roomno4};
if(g[0]!=null&&g[1]!=null&&g[2]!=null&&g[3]!=null) {
System.out.print("该宿舍已满");
return;
}
System.out.println("*************************************************************** \n" +
" 石家庄铁道大学 \n" +
" 学生公寓管理系统 v2022 \n" +
" 调整宿舍\n"+
"**************************************************************** \n" +
" 待调整宿舍号:"+a[ding1].roomno+"\n"+
" 1、床位1:" +a[ding1].roomno1 +"\n"+
" 2、床位2:" + a[ding1].roomno2+"\n"+
" 3、床位3:" + a[ding1].roomno3+"\n"+
" 4、床位4:" + a[ding1].roomno4+"\n"+
"****************************************************************");
}
public static void weisheng() {
int dingdian3=0;
System.out.println("*************************************************************** \n" +
" 石家庄铁道大学 \n" +
" 学生公寓管理系统 v2022 \n" +
" 宿舍卫生宿舍\n"+
"**************************************************************** \n"+
" 请输入待评价宿舍号: \n"+
"**************************************************************** \n");
var rur1=new Scanner(System.in);
String shuru3=rur1.next();
for(int i=0;i<10;i++) {
if(shuru3.equals(a[i].roomno)) {
dingdian3=i;
}
}
String g[]= {a[dingdian3].roomno1,a[dingdian3].roomno2,a[dingdian3].roomno3,a[dingdian3].roomno4};
if(g[0]==null&&g[1]==null&&g[2]==null&&g[3]==null) {
System.out.print("该宿舍为空宿舍");
System.out.print("输入有误");
return;
}
int shuru4 = 0;
System.out.println("*************************************************************** \n" +
" 石家庄铁道大学 \n" +
" 学生公寓管理系统 v2022 \n" +
" 宿舍卫生评价\n"+
"**************************************************************** \n" +
" 新宿舍号: " +a[dingdian3].roomno+"\n"+
" 1、床位1:" +a[dingdian3].roomno1 +"\n"+
" 2、床位2:" + a[dingdian3].roomno2+"\n"+
" 3、床位3:" + a[dingdian3].roomno3+"\n"+
" 4、床位4:" + a[dingdian3].roomno4+"\n"+
"****************************************************************\n" + " 输入宿舍卫生评价分数: \n"+
"****************************************************************"
);
System.out.print("请输入宿舍卫生评价分数");
var rur5=new Scanner(System.in);
shuru4=rur5.nextInt();
if((shuru4>=0)&&(shuru4<=100)) {
System.out.print("输入正确");
}
else if(shuru4>100){
System.out.print("请输入正确的宿舍卫生评价分数");
return;
}
else {
System.out.print("请输入正确的宿舍卫生评价分数");
return;
}
d[dingdian3] =shuru4;
System.out.println("*************************************************************** \n" +
" 石家庄铁道大学 \n" +
" 学生公寓管理系统 v2022 \n" +
" 宿舍卫生评价\n"+
"**************************************************************** \n" +
" 新宿舍号: " +a[dingdian3].roomno+"\n"+
" 1、床位1:" +a[dingdian3].roomno1 +"\n"+
" 2、床位2:" + a[dingdian3].roomno2+"\n"+
" 3、床位3:" + a[dingdian3].roomno3+"\n"+
" 4、床位4:" + a[dingdian3].roomno4+"\n"+
"****************************************************************\n"+
" 宿舍卫生评价分数:"+shuru4+"\n"+
"****************************************************************");
}
public static void panduan2(int a) {
if(a>=90&&a<=100) {
System.out.println("优秀");
}
else if(a>=80&&a<=90) {
System.out.println("良好");
}
else if(a>=60&&a<=80) {
System.out.println("及格");
}
else if(a>=0&&a<=60)
{
System.out.println("不及格");
}
}
public static void weishengchaxun() {
int i=0;
System.out.println("*************************************************************** \n" +
" -------石家庄铁道大学 \n" +
" 学生公寓管理系统 v2022 \n" +
"**************************************************************** \n" +
" 宿舍详细信息列表 \n"
);
for(i=0;i<sum;i++) {
System.out.print(i+1+"."+a[i].roomno+" "+d[i]+" ");
panduan2(d[i]);
System.out.print("\n ");
}
System.out.println("*************************************************************** \n");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
a[0]=new RoomInformation("9#101",null,null,null,null,0);
a[1]=new RoomInformation("9#102",null,null,null,null,0);
a[2]=new RoomInformation("9#103",null,null,null,null,0);
a[3]=new RoomInformation("9#104",null,null,null,null,0);
a[4]=new RoomInformation("9#105","20213856",null,null,null,0);
a[5]=new RoomInformation("9#106",null,"20213855",null,null,0);
a[6]=new RoomInformation("9#107",null,null,null,"20213755",0);
a[7]=new RoomInformation("9#108",null,null,null,null,0);
a[8]=new RoomInformation("9#109",null,null,null,null,0);
a[9]=new RoomInformation("9#201","232","2626","655","6565",0);
int choose = 0;
int vj=0;
int gh=0;
while(true) {
systemMenu();
System.out.println("请输入功能选项:");
var rur6=new Scanner(System.in);
choose=rur6.nextInt();
if(choose>=1&&choose<=6) {
vj=1;
}
else{
System.out.println("输入错误请重新输入");
}
switch (choose) {
case 1:
chaxun();
break;
case 2:
anpai();
break;
case 3:
tiaozheng();
break;
case 4:
weisheng();
break;
case 5:
weishengchaxun();
break;
}
System.out.println("是否继续,继续选择输入0,不继续输入1");
var rur7=new Scanner(System.in);
gh=rur7.nextInt();
if(gh==1) break;
}
}
}