1、定义公寓类,类名:RoomInformation,其中包括五个私有变量(roomno,stunno1,stunno2,stunno3,stunno4,hygienescore)。
变量 stunno1,stunno2、stunno3、stunno4 为字符串类型 String,用于存储学生的学号,长度8位(如果某个学号为空,表示没有数值,代表该宿舍空余一个床位;如果四个学号都为空,表示该宿舍为空宿舍)。
…………………….
…………………….
…………………….
④用户输入卫生评价分数,判断输入数值0-100之间,超出范围,提示“输入错误”,清空输入,回到当前界面,输入正确的数值,返回到“宿舍卫生评价”主界面。(0.5分)
…………………….
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 String getStunno1() {
return stunno1;
}
public String getStunno2() {
return stunno2;
}
public String getStunno3() {
return stunno3;
}
public String getStunno4() {
return stunno4;
}
public int getHygienescore() {
return hygienescore;
}
public void setRoomno(String roomno) {
this.roomno = roomno;
}
public void setStunno1(String stunno1) {
this.stunno1 = stunno1;
}
public void setStunno2(String stunno2) {
this.stunno2 = stunno2;
}
public void setStunno3(String stunno3) {
this.stunno3 = stunno3;
}
public void setStunno4(String stunno4) {
this.stunno4 = stunno4;
}
public void setHygienescore(int hygienescore) {
this.hygienescore = hygienescore;
}
public RoomInformation(String roomno, String stunno1, String stunno2, String stunno3, String stunno4,
int hygienescore) {
super();
this.roomno = roomno;
this.stunno1 = stunno1;
this.stunno2 = stunno2;
this.stunno3 = stunno3;
this.stunno4 = stunno4;
this.hygienescore = hygienescore;
}
}
public class RoomManagement {
static RoomInformation[] Room = new RoomInformation[10];
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
Room[0] = new RoomInformation("1#101", "20210001", "20210002", "20210003", "20210004", 100);
Room[1] = new RoomInformation("1#102", "20210021", "20210022", "20210023", "20210024", 90);
Room[2] = new RoomInformation("1#103", "20210031", "20210032", "20210033", "20210034", 80);
Room[3] = new RoomInformation("1#104", "20210041", "20210042", "20210043", "20210044", 70);
Room[4] = new RoomInformation("1#201", "", "", "", "", 0);
Room[5] = new RoomInformation("1#202", "", "", "", "", 0);
Room[6] = new RoomInformation("1#203", "", "", "", "", 0);
Room[7] = new RoomInformation("1#301", "20213011", "", "", "", 50);
Room[8] = new RoomInformation("1#302", "20213021", "", "", "", 40);
Room[9] = new RoomInformation("1#303", "20213031", "", "", "", 30);
while (true) {
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");
System.out.print("请选择:");
int a = sc.nextInt();
if (a == 1) {
chaxun();
} else if (a == 2) {
anpaixinsushe();
} else if (a == 3) {
tiaozheng();
} else if (a == 4) {
weishengpingjia();
} else if (a == 5) {
weichengchaxun();
} else {
System.out.println("该选项不存在");
}
}
}
public static void chaxun() {
System.out.print("***********************************************************\r\n"
+ " 石家庄铁道大学\r\n" + " 学生公寓管理系统v2022\r\n"
+ "***********************************************************\r\n"
+ " 宿舍详细信息列表\r\n");
for (int i = 0; i < 10; i++) {
int num = i + 1;
int people = 4;
System.out.print(" " + num + "、" + Room[i].getRoomno() + "\t");
if (Room[i].getStunno1() == "")
people--;
if (Room[i].getStunno2() == "")
people--;
if (Room[i].getStunno3() == "")
people--;
if (Room[i].getStunno4() == "")
people--;
System.out.print(people + "人\t");
if (people == 4)
System.out.print("已满\n");
else if (people == 3)
System.out.print("空1人\n");
else if (people == 2)
System.out.print("空2人\n");
else if (people == 1)
System.out.print("空3人\n");
else if (people == 0)
System.out.print("空宿舍\n");
}
System.out.print("***********************************************************\r\n");
}
public static void anpaixinsushe() {
System.out.print("***********************************************************\r\n"
+ " 石家庄铁道大学\r\n" + " 学生公寓管理系统v2022\r\n"
+ " 安排新宿舍\r\n"
+ "***********************************************************\r\n"
+ " 空宿舍详细信息列表\r\n");
int num = 1;
for (int i = 0; i < 10; i++) {
int people = 4;
if (Room[i].getStunno1() == "")
people--;
if (Room[i].getStunno2() == "")
people--;
if (Room[i].getStunno3() == "")
people--;
if (Room[i].getStunno4() == "")
people--;
if (people != 0)
continue;
System.out.print(" " + num + "、" + Room[i].getRoomno() + "\t");
System.out.print(people + "人\t");
if (people == 4)
System.out.print("已满\n");
else if (people == 3)
System.out.print("空1人\n");
else if (people == 2)
System.out.print("空2人\n");
else if (people == 1)
System.out.print("空3人\n");
else if (people == 0)
System.out.print("空宿舍\n");
num++;
}
System.out.print(" 请输入新宿舍号:");
String str = sc.next();
System.out.print("***********************************************************\r\n");
int newNum = -1;
for (int i = 0; i < 10; i++) {
if (Room[i].getRoomno().equals(str))
newNum = i;
}
if (newNum == -1) {
System.out.println("宿舍不存在");
String[] ma = null;
main(ma);
}
if (!(Room[newNum].getStunno1().equals("") && Room[newNum].getStunno2().equals("")
&& Room[newNum].getStunno3().equals("") && Room[newNum].getStunno4().equals("")))
System.out.println("该宿舍不是空宿舍,无法安排新生");
else {
while (true) {
System.out.print("***********************************************************\r\n"
+ " 石家庄铁道大学\r\n" + " 学生公寓管理系统v2022\r\n"
+ " 安排新宿舍\r\n"
+ "***********************************************************\r\n"
+ " 新宿舍号:" + str + "\r\n");
String s1, s2, s3, s4;
int YorN = 1;
if (Room[newNum].getStunno1().equals("")) {
System.out.print(" 1、床位1:" + Room[newNum].getStunno1());
s1 = sc.next();
if (s1.equals("END"))
break;
for (int i = 0; i < 10; i++) {
if (Room[i].getStunno1().equals(s1) || Room[i].getStunno2().equals(s1)
|| Room[i].getStunno3().equals(s1) || Room[i].getStunno4().equals(s1))
YorN = 0;
}
if (YorN == 0) {
System.out.println("该学生已分配宿舍");
continue;
}
Room[newNum].setStunno1(s1);
}
if (Room[newNum].getStunno2().equals("")) {
System.out.print(" 2、床位2:" + Room[newNum].getStunno2());
s2 = sc.next();
if (s2.equals("END"))
break;
for (int i = 0; i < 10; i++) {
if (Room[i].getStunno1().equals(s2) || Room[i].getStunno2().equals(s2)
|| Room[i].getStunno3().equals(s2) || Room[i].getStunno4().equals(s2))
YorN = 0;
}
if (YorN == 0) {
System.out.println("该学生已分配宿舍");
continue;
}
Room[newNum].setStunno2(s2);
}
if (Room[newNum].getStunno3().equals("")) {
System.out.print(" 3、床位3:" + Room[newNum].getStunno3());
s3 = sc.next();
if (s3.equals("END"))
break;
for (int i = 0; i < 10; i++) {
if (Room[i].getStunno1().equals(s3) || Room[i].getStunno2().equals(s3)
|| Room[i].getStunno3().equals(s3) || Room[i].getStunno4().equals(s3))
YorN = 0;
}
if (YorN == 0) {
System.out.println("该学生已分配宿舍");
continue;
}
Room[newNum].setStunno3(s3);
}
System.out.print(" 4、床位4:" + Room[newNum].getStunno4());
s4 = sc.next();
if (s4.equals("END"))
break;
for (int i = 0; i < 10; i++) {
if (Room[i].getStunno1().equals(s4) || Room[i].getStunno2().equals(s4)
|| Room[i].getStunno3().equals(s4) || Room[i].getStunno4().equals(s4))
YorN = 0;
}
if (YorN == 0) {
System.out.println("该学生已分配宿舍");
continue;
} else {
Room[newNum].setStunno4(s4);
System.out.println("该宿舍已满");
break;
}
}
}
}
public static void tiaozheng() {
System.out.print("***********************************************************\r\n"
+ " 石家庄铁道大学\r\n" + " 学生公寓管理系统v2022\r\n"
+ " 调整宿舍\r\n"
+ "***********************************************************\r\n"
+ " 有空床位宿舍详细信息列表\r\n");
int num = 1;
for (int i = 0; i < 10; i++) {
int people = 4;
if (Room[i].getStunno1() == "")
people--;
if (Room[i].getStunno2() == "")
people--;
if (Room[i].getStunno3() == "")
people--;
if (Room[i].getStunno4() == "")
people--;
if (people == 4)
continue;
System.out.print(" " + num + "、" + Room[i].getRoomno() + "\t");
System.out.print(people + "人\t");
if (people == 4)
System.out.print("已满\n");
else if (people == 3)
System.out.print("空1人\n");
else if (people == 2)
System.out.print("空2人\n");
else if (people == 1)
System.out.print("空3人\n");
else if (people == 0)
System.out.print("空宿舍\n");
num++;
}
System.out.print(" 请输入待调整宿舍号:");
String str = sc.next();
System.out.print("***********************************************************\r\n");
int newNum = -1;
for (int i = 0; i < 10; i++) {
if (Room[i].getRoomno().equals(str))
newNum = i;
}
if (newNum == -1) {
System.out.println("宿舍不存在");
String[] ma = null;
main(ma);
}
if (!(Room[newNum].getStunno1().equals("") || Room[newNum].getStunno2().equals("")
|| Room[newNum].getStunno3().equals("") || Room[newNum].getStunno4().equals("")))
System.out.println("该宿舍不是空宿舍,无法安排新生");
else {
while (true) {
System.out.print("***********************************************************\r\n"
+ " 石家庄铁道大学\r\n" + " 学生公寓管理系统v2022\r\n"
+ " 调整宿舍\r\n"
+ "***********************************************************\r\n"
+ " 待调整宿舍号:" + str + "\r\n");
String s1, s2, s3, s4;
int YorN = 1;
int number = 1;
if (Room[newNum].getStunno1().equals("")) {
System.out.print(" " + number + "、床位1:" + Room[newNum].getStunno1());
s1 = sc.next();
if (s1.equals("END"))
break;
for (int i = 0; i < 10; i++) {
if (Room[i].getStunno1().equals(s1) || Room[i].getStunno2().equals(s1)
|| Room[i].getStunno3().equals(s1) || Room[i].getStunno4().equals(s1))
YorN = 0;
}
if (YorN == 0) {
System.out.println("该学生已分配宿舍");
continue;
}
Room[newNum].setStunno1(s1);
number++;
}
if (Room[newNum].getStunno2().equals("")) {
System.out.print(" " + number + "、床位2:" + Room[newNum].getStunno2());
s2 = sc.next();
if (s2.equals("END"))
break;
for (int i = 0; i < 10; i++) {
if (Room[i].getStunno1().equals(s2) || Room[i].getStunno2().equals(s2)
|| Room[i].getStunno3().equals(s2) || Room[i].getStunno4().equals(s2))
YorN = 0;
}
if (YorN == 0) {
System.out.println("该学生已分配宿舍");
continue;
}
Room[newNum].setStunno2(s2);
number++;
}
if (Room[newNum].getStunno3().equals("")) {
System.out.print(" " + number + "、床位3:" + Room[newNum].getStunno3());
s3 = sc.next();
if (s3.equals("END"))
break;
for (int i = 0; i < 10; i++) {
if (Room[i].getStunno1().equals(s3) || Room[i].getStunno2().equals(s3)
|| Room[i].getStunno3().equals(s3) || Room[i].getStunno4().equals(s3))
YorN = 0;
}
if (YorN == 0) {
System.out.println("该学生已分配宿舍");
continue;
}
Room[newNum].setStunno3(s3);
number++;
}
System.out.print(" " + number + "、床位4:" + Room[newNum].getStunno4());
s4 = sc.next();
if (s4.equals("END"))
break;
for (int i = 0; i < 10; i++) {
if (Room[i].getStunno1().equals(s4) || Room[i].getStunno2().equals(s4)
|| Room[i].getStunno3().equals(s4) || Room[i].getStunno4().equals(s4))
YorN = 0;
}
if (YorN == 0) {
System.out.println("该学生已分配宿舍");
continue;
} else {
Room[newNum].setStunno4(s4);
System.out.println("该宿舍已满");
break;
}
}
}
}
public static void weishengpingjia() {
while (true) {
System.out.print("***********************************************************\r\n"
+ " 石家庄铁道大学\r\n" + " 学生公寓管理系统v2022\r\n"
+ " 宿舍卫生评价\r\n"
+ "***********************************************************\r\n" + " 请输入待评价宿舍号:");
String str = sc.next();
System.out.print("***********************************************************\r\n");
int newNum = -1;
for (int i = 0; i < 10; i++) {
if (Room[i].getRoomno().equals(str))
newNum = i;
}
if (newNum == -1) {
System.out.println("宿舍不存在");
String[] ma = null;
main(ma);
}
int people = 4;
if (Room[newNum].getStunno1() == "")
people--;
if (Room[newNum].getStunno2() == "")
people--;
if (Room[newNum].getStunno3() == "")
people--;
if (Room[newNum].getStunno4() == "")
people--;
if (people == 0) {
System.out.print("该宿舍为空宿舍");
continue;
} else {
while (true) {
System.out.print("***********************************************************\r\n"
+ " 石家庄铁道大学\r\n" + " 学生公寓管理系统v2022\r\n"
+ " 宿舍卫生评价\r\n"
+ "***********************************************************\r\n"
+ " 宿舍号:" + str + "\r\n");
int number = 1;
if (!(Room[newNum].getStunno1().equals(""))) {
System.out.println(" " + number + "、床位1:" + Room[newNum].getStunno1());
number++;
}
if (!(Room[newNum].getStunno2().equals(""))) {
System.out.println(" " + number + "、床位2:" + Room[newNum].getStunno2());
number++;
}
if (!(Room[newNum].getStunno3().equals(""))) {
System.out.println(" " + number + "、床位3:" + Room[newNum].getStunno3());
number++;
}
if (!(Room[newNum].getStunno4().equals(""))) {
System.out.println(" " + number + "、床位4:" + Room[newNum].getStunno4());
}
System.out.print("输入宿舍卫生评价分数:");
int a = sc.nextInt();
System.out.print("***********************************************************\r\n");
if (a >= 0 && a <= 100) {
break;
} else {
System.out.println("输入错误");
}
}
}
}
}
public static void weichengchaxun() {
System.out.print("***********************************************************\r\n"
+ " 石家庄铁道大学\r\n" + " 学生公寓管理系统v2022\r\n"
+ "***********************************************************\r\n"
+ " 卫生检查情况查询\r\n");
for (int i = 0; i < 10; i++) {
int num = i + 1;
System.out.print(" " + num + "、" + Room[i].getRoomno() + "\t");
System.out.print(Room[i].getHygienescore() + "\t");
if (Room[i].getHygienescore() >= 90)
System.out.println("优秀");
else if (Room[i].getHygienescore() >= 80)
System.out.println("良好");
else if (Room[i].getHygienescore() >= 60)
System.out.println("合格");
else
System.out.println("不合格");
}
System.out.print("***********************************************************\r\n");
}
}