反思
9月2号进行的测试中发现了我的不足,这次的题没做出来主要有两点,第一是练习少,考试的时候有点紧张,第二就是卡在开头的一个地方无法运行,导致后来没做,回宿舍之后通过csdn解决了这一问题,然后完成了程序,下面是源程序代码
import java .util.Scanner;
class RoomInformation
{
private String roomno;
private String stunno1;
private String stunno2;
private String stunno3;
private String stunno4;
private int hygienescore=0;
//获取初始值和获得初始值
public String getroomno()
{
return roomno;
}
public void setroomno(String roomnok)
{
roomno=roomnok;
}
public String getstunno1()
{
return stunno1;
}
public void setstunno1(String stunnok)
{
stunno1=stunnok;
}
public String getstunno2()
{
return stunno2;
}
public void setstunno2(String stunnok)
{
stunno2=stunnok;
}
public String getstunno3()
{
return stunno3;
}
public void setstunno3(String stunnok)
{
stunno3=stunnok;
}
public String getstunno4()
{
return stunno4;
}
public void setstunno4(String stunnok)
{
stunno4=stunnok;
}
public int gethygienescore()
{
return hygienescore;
}
public void sethygienescore(int hygienescorek)
{
hygienescore =hygienescorek;
}
}
public class RoomManagement
{
//存储十个宿舍的基本信息
RoomInformation[] room=new RoomInformation[10];
public void firstinput()
{
room[0]=new RoomInformation();
room[0].setroomno("9#100");
room[0].setstunno1("20210001");
room[0].setstunno2("20210002");
room[0].setstunno3("20210003");
room[0].setstunno4("20210004");
room[1]=new RoomInformation();
room[1].setroomno("9#101");
room[1].setstunno1("20210005");
room[1].setstunno2("20210006");
room[1].setstunno3("20210007");
room[1].setstunno4("20210008");
room[2]=new RoomInformation();
room[2].setroomno("9#102");
room[2].setstunno1("20210009");
room[2].setstunno2("20210010");
room[2].setstunno3("20210011");
room[2].setstunno4("20210012");
room[3]=new RoomInformation();
room[3].setroomno("9#103");
room[3].setstunno1("20210013");
room[3].setstunno2("20210014");
room[3].setstunno3("20210015");
room[3].setstunno4("20210016");
room[4]=new RoomInformation();
room[4].setroomno("9#104");
room[5]=new RoomInformation();
room[5].setroomno("9#105");
room[6]=new RoomInformation();
room[6].setroomno("9#106");
room[7]=new RoomInformation();
room[7].setroomno("9#107");
room[7].setstunno1("20210017");
room[7].setstunno2("20210018");
room[7].setstunno3("20210019");
room[8]=new RoomInformation();
room[8].setroomno("9#108");
room[8].setstunno3("20210020");
room[8].setstunno4("20210021");
room[9]=new RoomInformation();
room[9].setroomno("9#109");
room[9].setstunno1("20210022");
}
//宿舍管理系统的主界面
public void zhujiemian()
{
System.out.print("***********************************************************\r\n"
+ " 石家庄铁道大学\r\n"
+" 学生公寓管理系统v2022\r\n"
+ "***********************************************************\r\n"
+ " 1、宿舍查询\r\n"
+ " 2、安排新宿舍\r\n"
+ " 3、调整宿舍\r\n"
+ " 4、宿舍卫生评价\r\n"
+ " 5、卫生检查情况查询\r\n"
+ "**********************************************************\r\n");
}
//检测空床位信息
public int howmanystudent(RoomInformation room)
{
int sum,num1,num2,num3,num4;
if(room.getstunno1()==null) num1=0;
else num1=1;
if(room.getstunno2()==null) num2=0;
else num2=1;
if(room.getstunno3()==null) num3=0;
else num3=1;
if(room.getstunno4()==null) num4=0;
else num4=1;
sum=num1+num2+num3+num4;
return sum;
}
//检测并显示空床位信息
public void showroominformation()
{
int i=0,j=1;
System.out.print("***********************************************************\r\n"
+ " 石家庄铁道大学\r\n"
+" 学生公寓管理系统v2022\r\n"
+ "***********************************************************\r\n");
for(i=0;i<10;j++,i++)
{
int sum,num1,num2,num3,num4;
if(room[i].getstunno1()==null) num1=0;
else num1=1;
if(room[i].getstunno2()==null) num2=0;
else num2=1;
if(room[i].getstunno3()==null) num3=0;
else num3=1;
if(room[i].getstunno4()==null) num4=0;
else num4=1;
sum=num1+num2+num3+num4;
System.out.print(j+"、9#10"+i+" "+sum+"人");
if(sum==4)
{
System.out.print(" 已满\n");
}
else if(sum==1||sum==2||sum==3)
{
int yu=4-sum;
System.out.print(" 空"+yu+"人\n");
}
else System.out.print(" 空宿舍\n");
}
System.out.print("***********************************************************\n");
}
//学号是否重复
public int xuehaochongfu(String xuehao)
{
for(int i=0;i<10;i++)
{
if(room[i].getstunno1()!=null)
{
if(room[i].getstunno1().equals(xuehao)) return 1;
}
if(room[i].getstunno2()!=null)
{
if(room[i].getstunno2().equals(xuehao)) return 1;
}
if(room[i].getstunno3()!=null)
{
if(room[i].getstunno3().equals(xuehao)) return 1;
}
if(room[i].getstunno4()!=null)
{
if(room[i].getstunno4().equals(xuehao)) return 1;
}
}
return 0;
}
//安排新宿舍
public void shuownullroom()
{
System.out.print("***********************************************************\r\n"
+ " 石家庄铁道大学\r\n"
+" 学生公寓管理系统v2022\r\n"
+ " 安排新宿舍\r\n"
+ "***********************************************************\r\n"
+" 空宿舍详细信息列表\r\n");
for(int i=0,j=0;i<10;i++)
{
if(howmanystudent(room[i])==0)
{
j++;
System.out.print(" "+j+"、9#10"+i+" 0人 空宿舍\n");
}
}
System.out.print(" 请输入新宿舍号:XXXXX\r\n"
+ "**********************************************************\r\n");
}
public int anpaisusuhe()
{
Scanner scan=new Scanner(System.in);
String sushehao=scan.next();
int i=0,j=0;
for(;i<10;i++)
{
if(room[i].getroomno().equals(sushehao))
{
if(howmanystudent(room[i])!=0)
{
System.out.print("该宿舍不是空宿舍,无法安排新生\n");
j=-1;
break;
}
else
{
j=i;
break;
}
}
}
return j;
}
public void xuanxushe(int i)
{
System.out.print("***********************************************************\r\n"
+ " 石家庄铁道大学\r\n"
+ " 学生公寓管理系统v2022\r\n"
+ " 安排新宿舍\r\n"
+ "***********************************************************\r\n"
+ " 新宿舍号:\r\n"
+ " 1、床位1:XXXXX(学号1)\r\n"
+ " 2、床位2:XXXXX(学号2)\r\n"
+ " 3、床位3:XXXXX(学号3)\r\n"
+ " 4、床位4:XXXXX(学号4)\r\n"
+ "**********************************************************\r\n");
Scanner scan=new Scanner(System.in);
String a;
for(;;)
{
a=scan.next();
if(a.equals("END"))break;
if(xuehaochongfu(a)==1)
{
System.out.print("该学生已分配宿舍\n");
continue;
}
room[i].setstunno1(a);
a=scan.next();
if(a.equals("END"))break;
if(xuehaochongfu(a)==1)
{
System.out.print("该学生已分配宿舍\n");
continue;
}
room[i].setstunno2(a);
a=scan.next();
if(a.equals("END"))break;
if(xuehaochongfu(a)==1)
{
System.out.print("该学生已分配宿舍\n");
continue;
}
room[i].setstunno3(a);
a=scan.next();
if(a.equals("END"))break;
if(xuehaochongfu(a)==1)
{
System.out.print("该学生已分配宿舍\n");
continue;
}
room[i].setstunno4(a);
System.out.print("提示该宿舍已满\n");
break;
}
}
//选择3调整宿舍功能
public void tiaozhengsushe()
{
System.out.print("***********************************************************\r\n"
+" 石家庄铁道大学\r\n"
+ " 学生公寓管理系统v2022\r\n"
+ " 调整宿舍\r\n"
+ "***********************************************************\r\n"
+" 有空床位宿舍详细信息列表\r\n");
int i=0,j=1;
for(i=0;i<10;i++)
{
int sum,num1,num2,num3,num4;
if(room[i].getstunno1()==null) num1=0;
else num1=1;
if(room[i].getstunno2()==null) num2=0;
else num2=1;
if(room[i].getstunno3()==null) num3=0;
else num3=1;
if(room[i].getstunno4()==null) num4=0;
else num4=1;
sum=num1+num2+num3+num4;
if(sum==1||sum==2||sum==3)
{
System.out.print(" "+j+"、9#10"+i+" "+sum+"人");
int yu=4-sum;
System.out.print(" 空"+yu+"人\n");
j++;
}
}
System.out.print(" 请输入待调整宿舍号:XXXXX\r\n"
+ "**********************************************************\r\n");
Scanner scan=new Scanner(System.in);
String sushehao=scan.next();
for(i=0;i<10;i++)
{
if(room[i].getroomno().equals(sushehao))
{
if(howmanystudent(room[i])==4)
{
System.out.print("该宿舍没有空床位,无法调整\n");
break;
}
else
{
System.out.print("***********************************************************\r\n"
+" 石家庄铁道大学\r\n"
+ " 学生公寓管理系统v2022\r\n"
+ " 宿舍卫生评价\r\n"
+ "***********************************************************\r\n"
+ " 宿舍号:"
+sushehao+"\n");
if(room[i].getstunno1()!=null)System.out.print(" 1、床位1:"+room[i].getstunno1()+"\n");
if(room[i].getstunno2()!=null)System.out.print(" 2、床位2:"+room[i].getstunno2()+"\n");
if(room[i].getstunno3()!=null)System.out.print(" 3、床位3:"+room[i].getstunno3()+"\n");
if(room[i].getstunno4()!=null)System.out.print(" 4、床位4:"+room[i].getstunno4()+"\n");
System.out.print(" 用户输入:XXXXXXX\r\n"
+ "**********************************************************\r\n");
}
}
}
}
//评价宿舍
public void pingjiasushe()
{
System.out.print("***********************************************************\r\n"
+ " 石家庄铁道大学\r\n"
+ " 学生公寓管理系统v2022\r\n"
+ " 宿舍卫生宿舍\r\n"
+ "***********************************************************\r\n"
+ " 请输入待评价宿舍号:XXXXX\r\n"
+ "**********************************************************\r\n");
Scanner scan=new Scanner(System.in);
String sushehao=scan.next();
for(int i=0;i<10;i++)
{
if(room[i].getroomno().equals(sushehao))
{
if(howmanystudent(room[i])==0)
{
System.out.print("该宿舍为空宿舍\n");
System.out.print("***********************************************************\r\n"
+ " 石家庄铁道大学\r\n"
+ " 学生公寓管理系统v2022\r\n"
+ " 宿舍卫生宿舍\r\n"
+ "***********************************************************\r\n"
+ " 请输入待评价宿舍号:XXXXX\r\n"
+ "**********************************************************\r\n");
sushehao=scan.next();
i=0;
}
if(howmanystudent(room[i])!=0)
{
System.out.print("***********************************************************\r\n"
+" 石家庄铁道大学\r\n"
+ " 学生公寓管理系统v2022\r\n"
+ " 宿舍卫生评价\r\n"
+ "***********************************************************\r\n"
+ " 宿舍号:"
+sushehao+"\n");
if(room[i].getstunno1()!=null)System.out.print(" 1、床位1:"+room[i].getstunno1()+"\n");
if(room[i].getstunno2()!=null)System.out.print(" 2、床位2:"+room[i].getstunno2()+"\n");
if(room[i].getstunno3()!=null)System.out.print(" 3、床位3:"+room[i].getstunno3()+"\n");
if(room[i].getstunno4()!=null)System.out.print(" 4、床位4:"+room[i].getstunno4()+"\n");
System.out.print(" 输入宿舍卫生评价分数:XXXXXXX\r\n"
+ "**********************************************************\r\n");
int pingfen=scan.nextInt();
for(;pingfen<0||pingfen>100;)
{
pingfen=scan.nextInt();
}
room[i].sethygienescore(pingfen);
break;
}
}
}
}
//卫生检查情况
public void weishengjianchaqingkuang()
{
System.out.print("***********************************************************\r\n"
+" 石家庄铁道大学\r\n"
+ " 学生公寓管理系统v2022\r\n"
+ " 卫生检查情况查询\r\n"
+ "***********************************************************\r\n"
+" 宿舍卫生检查情况信息\r\n");
for(int i=0,j=1;i<10;i++)
{
if(howmanystudent(room[i])!=0)
{
System.out.print(" "+j+"、9#10"+i+" "+room[i].gethygienescore());
if(room[i].gethygienescore()>=90)System.out.print(" 优秀\n");
else if(room[i].gethygienescore()>=80)System.out.print(" 良好\n");
else if(room[i].gethygienescore()>=60)System.out.print(" 合格\n");
else System.out.print(" 不合格\n");
}
}
System.out.print("***********************************************************\r\n");
}
public static void main(String[] agrs)
{
RoomManagement sushe=new RoomManagement();
sushe.firstinput();
Scanner scan=new Scanner(System.in);
for(;;)
{sushe.zhujiemian();
int choice=scan.nextInt();
for(;;)
{
if(choice==1||choice==2||choice==3||choice==4||choice==5) break;
else
{
System.out.print("选项错误请重新输入:");
choice=scan.nextInt();
}
}
//选择1宿舍查询功能
if(choice==1) sushe.showroominformation();
//选择2安排新宿舍功能
if(choice==2)
{
sushe.shuownullroom();
int temp=sushe.anpaisusuhe();
for(;temp==-1;)
{
temp=sushe.anpaisusuhe();
}
sushe.xuanxushe(temp);
}
//选择3调整宿舍功能
if(choice==3)
sushe.tiaozhengsushe();
//选择4宿舍卫生评价
if(choice==4)
sushe.pingjiasushe();
//选择5卫生检查情况查询功能
if(choice==5)
sushe.weishengjianchaqingkuang();
}
}
}