首页 > 其他分享 >第二次

第二次

时间:2022-09-04 17:34:41浏览次数:36  
标签:System get renshu equals stu println 第二次

紧接上次随笔,本次为开学测试修改版本,修复bug,但代码仍有优化之处,下周会再次优化

package java1;

import java.util.ArrayList;
import java.util.Scanner;

 


public class show {
public static void main(String[] args) {
int a = 0;
ArrayList<RoomManagement> stu = new ArrayList<RoomManagement>();
Scanner sr = new Scanner(System.in);
while (true) {
System.out.println("输入数据");
stu.add(new RoomManagement(sr.next(),sr.next(),sr.next(),sr.next(),sr.next(),sr.nextInt()));

System.out.println("是否继续(如果不继续输入1)");
if (sr.nextInt() == 1) {
break;
}
}
/*RoomManagement[] stu = new RoomManagement[10];
stu[0] = new RoomManagement("9#100", "2021300", "2021301", "2021302", "2021303", 0);
stu[1] = new RoomManagement("9#101", "2021400", "2021401", "2021402", "2021403", 0);
stu[2] = new RoomManagement("9#102", "2021500", "2021501", "2021502", "2021503", 0);
stu[3] = new RoomManagement("9#103", null, null, null, null, 0);
stu[4] = new RoomManagement("9#104", null, null, null, null, 0);
stu[5] = new RoomManagement("9#105", null, null, null, null, 0);
stu[6] = new RoomManagement("9#106", "2021600", "2021601", "2021602", null, 0);
stu[7] = new RoomManagement("9#107", "2021700", "2021701", "2021702", null, 0);
stu[8] = new RoomManagement("9#108", "2021800", "2021801", "2021802", null, 0);
stu[9] = new RoomManagement("9#109", "2021900", "2021901", "2021902", null, 0);*/
while (true) {
Menu.show();
Scanner sc = new Scanner(System.in);
a = sc.nextInt();
if (a == 1) {
Menu.sushechaxun(stu);
} else if (a == 2) {
Menu.anpaisushe(stu);
} else if (a == 3) {
Menu.tiaozhengsushe(stu);
} else if (a == 4) {
Menu.weishengpingjia(stu);
} else if (a == 5) {
Menu.shencha(stu);
} else {
System.out.println("请重新输入");
}

}
}
}

package java1;

import java.util.ArrayList;
import java.util.Scanner;

 

public class Menu {
public static void show() {
System.out.println("***********************************************************石家庄铁道大学\r\n"
+ "学生公寓管理系统v2022\r\n" + "***********************************************************\r\n" + "1、宿舍查询\r\n"
+ "2、安排新宿舍\r\n" + "3、调整宿舍\r\n" + "4、宿舍卫生评价\r\n" + "5、卫生检查情况查询\r\n"
+ "**********************************************************");
}

public static void sushechaxun(ArrayList <RoomManagement> stu) {
int[] renshu = new int[stu.size()];
for (int i = 0; i < stu.size(); i++) {
renshu[i] = 4;
if (stu.get(i).getStunno1().equals("null") == true) {
renshu[i] = renshu[i] - 1;
}
if (stu.get(i).getStunno2().equals("null") == true) {
renshu[i] = renshu[i] - 1;
}
if (stu.get(i).getStunno3().equals("null") == true) {
renshu[i] = renshu[i] - 1;
}
if (stu.get(i).getStunno4().equals("null") == true) {
renshu[i] = renshu[i] - 1;
}
if (renshu[i] == 4) {
System.out.println(stu.get(i).getRoomno() + " " + renshu[i] + "人" + " " + "已满");
}
if (renshu[i] == 0) {
System.out.println(stu.get(i).getRoomno() + " " + renshu[i] + "人" + " " + "空宿舍");

}

if ((renshu[i] != 4) && (renshu[i] != 0))
{
int b;
b = 4 - renshu[i];
System.out.println(stu.get(i).getRoomno() + " " + renshu[i] + "人" + " " + "空" + b + "人");
}
}
System.out.println("…………………….\r\n" + "**********************************************************");

}

public static void anpaisushe(ArrayList <RoomManagement> stu) {
int j = 0;
int k = 1;
System.out
.println("***********************************************************石家庄铁道大学\r\n" + "学生公寓管理系统v2022\r\n"
+ "安排新宿舍\r\n" + "***********************************************************\r\n" + "新宿舍号:");
int[] renshu = new int[stu.size()];
int i;
for (i = 0; i < stu.size(); i++) {
renshu[i] = 4;
if (stu.get(i).getStunno1().equals("null")) {
renshu[i] = renshu[i] - 1;
}
if (stu.get(i).getStunno2().equals("null")) {
renshu[i] = renshu[i] - 1;
}
if (stu.get(i).getStunno3().equals("null")) {
renshu[i] = renshu[i] - 1;
}
if (stu.get(i).getStunno4().equals("null")) {
renshu[i] = renshu[i] - 1;
}
if (renshu[i] == 0) {
System.out.println(stu.get(i).getRoomno() + " " + renshu[i] + "人" + " " + "空宿舍");

}
}
System.out.println("请输入新宿舍号:XXXXX\r\n" + "**********************************************************");
String sushehao;
Scanner sushehao1 = new Scanner(System.in);
sushehao = sushehao1.next();
abc: for (i = 0; i < stu.size(); i++) {
if (stu.get(i).getRoomno().equals(sushehao)) {
k = 0;
if ((stu.get(i).getStunno1().equals("null") == false) || (stu.get(i).getStunno2().equals("null") == false) || (stu.get(i).getStunno3().equals("null") == false)
|| (stu.get(i).getStunno4().equals("null") == false)) {
System.out.println("该宿舍不是空宿舍,无法安排新生");
} else {
System.out.println("***********************************************************石家庄铁道大学\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"
+ "**********************************************************");
for (i = 0; i < 4; i++) {
int a = 0;
Scanner xuehao = new Scanner(System.in);
if (a == 0) {
String xuehao1;
xuehao1 = xuehao.next();
if (xuehao1.equals("END")) {
break abc;
}
stu.get(i).setStunno1(xuehao1);
a = 1;
}
if (a == 1) {
String xuehao2;
xuehao2 = xuehao.next();
if (xuehao2.equals("END")) {
break abc;
}
if (stu.get(i).getStunno1().equals(xuehao2)) {
System.out.println("该学生已分配宿舍");
break;
} else {
stu.get(i).setStunno2(xuehao2);
a = 2;
}
}
if (a == 2) {
String xuehao3;
xuehao3 = xuehao.next();
if (xuehao3.equals("END")) {
break abc;
}
if ((stu.get(i).getStunno1() == xuehao3) || (stu.get(i).getStunno2() == xuehao3)) {
System.out.println("该学生已分配宿舍");
break;
} else {
stu.get(i).setStunno3(xuehao3);
a = 3;
}
}
if (a == 3) {
String xuehao4;
xuehao4 = xuehao.next();
if (xuehao4.equals("END")) {
break abc;
}
if ((stu.get(i).getStunno1() == xuehao4) || (stu.get(i).getStunno2() == xuehao4)
|| (stu.get(i).getStunno3() == xuehao4)) {
System.out.println("该学生已分配宿舍");
break;
} else {
stu.get(i).setStunno4(xuehao4);
a = 4;
j = 1;
break abc;
}
}

}
if (j == 1)
System.out.println("该宿舍已满");
}
}

}
if(k == 1)
{
System.out.println("宿舍不存在");
}

}

public static void tiaozhengsushe(ArrayList <RoomManagement> stu) {
System.out.println("***********************************************************石家庄铁道大学\r\n"
+ "学生公寓管理系统v2022\r\n" + "调整宿舍\r\n" + "***********************************************************\r\n"
+ "有空床位宿舍详细信息列表");
int[] renshu = new int[stu.size()];
int i, j;
j = 0;
for (i = 0; i < stu.size(); i++) {
renshu[i] = 4;
if (stu.get(i).getStunno1().equals("null")) {
renshu[i] = renshu[i] - 1;
}
if (stu.get(i).getStunno2().equals("null")) {
renshu[i] = renshu[i] - 1;
}
if (stu.get(i).getStunno3().equals("null")) {
renshu[i] = renshu[i] - 1;
}
if (stu.get(i).getStunno4().equals("null")) {
renshu[i] = renshu[i] - 1;
}
if ((renshu[i] != 4) && (renshu[i] != 0)) {
int b;
b = 4 - renshu[i];
System.out.println(stu.get(i).getRoomno() + " " + renshu[i] + "人" + " " + "空" + b + "人");
}

}
System.out.println("**********************************************************");
String newsushehao;
Scanner sushehao2 = new Scanner(System.in);
System.out.println("请输入宿舍号");
newsushehao = sushehao2.nextLine();
ab: for (i = 0; i < stu.size(); i++) {
if (stu.get(i).getRoomno().equals(newsushehao)) {
j = 1;
if ((stu.get(i).getStunno1().equals("null") == false)&& (stu.get(i).getStunno2().equals("null") == false) && (stu.get(i).getStunno3().equals("null") == false)
&& (stu.get(i).getStunno4().equals("null") == false)) {
System.out.println("该宿舍无法调整");
} else {
System.out.println("***********************************************************石家庄铁道大学\r\n"
+ "学生公寓管理系统v2022\r\n" + "调整宿舍\r\n"
+ "***********************************************************\r\n" + "待调整宿舍号:9#103\r\n"
+ "1、床位1:" + stu.get(i).getStunno1() + "2、床位2:" + stu.get(i).getStunno2() + "3、床位3:"
+ stu.get(i).getStunno3() + "4、床位4:" + stu.get(i).getStunno4() + "\r\n"
+ "**********************************************************");
Scanner xuehao1 = new Scanner(System.in);
String xuehao;
xuehao = xuehao1.next();
if (xuehao.equals("END")) {
break ab;
}
Scanner chuangwei1 = new Scanner(System.in);
int chuangwei;
chuangwei = chuangwei1.nextInt();
if (chuangwei == 1) {
if ((stu.get(i).getStunno2().equals(xuehao) == true) || (stu.get(i).getStunno4().equals(xuehao) == true)
|| (stu.get(i).getStunno3().equals(xuehao) == true))
System.out.println("学号重复");
else {
stu.get(i).setStunno1(xuehao);

}
} else if (chuangwei == 2) {
if ((stu.get(i).getStunno1().equals(xuehao) == true) || (stu.get(i).getStunno4().equals(xuehao) == true)
|| (stu.get(i).getStunno3().equals(xuehao) == true))
System.out.println("学号重复");
else
stu.get(i).setStunno2(xuehao);
} else if (chuangwei == 3) {
if ((stu.get(i).getStunno1().equals(xuehao) == true) || (stu.get(i).getStunno2().equals(xuehao) == true)
|| (stu.get(i).getStunno4().equals(xuehao) == true))
System.out.println("学号重复");
else
stu.get(i).setStunno3(xuehao);
} else if (chuangwei == 4) {
if ((stu.get(i).getStunno1().equals(xuehao) == true) || (stu.get(i).getStunno2().equals(xuehao) == true)
|| (stu.get(i).getStunno3().equals(xuehao) == true))
System.out.println("学号重复");
else
stu.get(i).setStunno4(xuehao);
}

}
}

}
if (j == 0) {
System.out.println("宿舍不存在");
}

}

public static void weishengpingjia(ArrayList <RoomManagement> stu) {
int i, j;
j = 1;
System.out.println("***********************************************************石家庄铁道大学\r\n"
+ "学生公寓管理系统v2022\r\n" + "宿舍卫生评价\r\n" + "***********************************************************\r\n"
+ "请输入待评价宿舍号:XXXXX\r\n" + "**********************************************************");
String sushehao;
Scanner sushehao1 = new Scanner(System.in);
sushehao = sushehao1.next();
for (i = 0; i < stu.size(); i++) {
if (stu.get(i).getRoomno().equals(sushehao)) {
j = 0;
if ((stu.get(i).getStunno1().equals("null") == true) && (stu.get(i).getStunno2().equals("null") == true) && (stu.get(i).getStunno3().equals("null") == true)
&& (stu.get(i).getStunno4().equals("null")== true)) {
System.out.println("宿舍为空宿舍");
} else {
System.out.println("***********************************************************石家庄铁道大学\r\n"
+ "学生公寓管理系统v2022\r\n" + "宿舍卫生评价\r\n"
+ "***********************************************************\r\n" + "宿舍号:"
+ stu.get(i).getRoomno() + "1、床位1:" + stu.get(i).getStunno1() + "2、床位2:" + stu.get(i).getStunno2()
+ "3、床位3:" + stu.get(i).getStunno3() + "4、床位4:" + stu.get(i).getStunno4() + "\r\n"
+ "输入宿舍卫生评价分数:XXXXXXX\r\n" + "**********************************************************");
Scanner fenshu1 = new Scanner(System.in);
int fenshu;
fenshu = fenshu1.nextInt();
if (fenshu > 100 || fenshu < 0) {
System.out.println("错误信息");
} else {
stu.get(i).setHygienescore(fenshu);
break;
}
}
}

}
if (j == 1) {
System.out.println("宿舍不存在");
}

}

public static void shencha(ArrayList <RoomManagement> stu) {
int i;
System.out.println("***********************************************************石家庄铁道大学\r\n"
+ "学生公寓管理系统v2022\r\n" + "卫生检查情况查询\r\n"
+ "***********************************************************\r\n" + "宿舍卫生检查情况信息");
for (i = 0; i < stu.size(); i++) {
if (stu.get(i).getHygienescore() >= 0 && stu.get(i).getHygienescore() <= 60) {
System.out.println(stu.get(i).getRoomno() + " " + stu.get(i).getHygienescore() + "不合格");

} else if (stu.get(i).getHygienescore() > 60 && stu.get(i).getHygienescore() <= 80) {
System.out.println(stu.get(i).getRoomno() + " " + stu.get(i).getHygienescore() + "合格");
} else if (stu.get(i).getHygienescore() > 80 && stu.get(i).getHygienescore() <= 90) {
System.out.println(stu.get(i).getRoomno() + " " + stu.get(i).getHygienescore() + "良好");
} else if (stu.get(i).getHygienescore() > 90 && stu.get(i).getHygienescore() <= 100) {
System.out.println(stu.get(i).getRoomno() + " " + stu.get(i).getHygienescore() + "优秀");
}
}
System.out.println("**********************************************************");
}
}

package Chongxie;

public class RoomManagement {
private String roomno;
private String stunno1;
private String stunno2;
private String stunno3;
private String stunno4;
private int hygienescore;

public RoomManagement() {
super();
}
public RoomManagement(String roomno) {
this.roomno = roomno;
}
public RoomManagement(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 String getRoomno() {
return roomno;
}
public void setRoomno(String roomno) {
this.roomno = roomno;
}
public String getStunno1() {
return stunno1;
}
public void setStunno1(String stunno1) {
this.stunno1 = stunno1;
}
public String getStunno2() {
return stunno2;
}
public void setStunno2(String stunno2) {
this.stunno2 = stunno2;
}
public String getStunno3() {
return stunno3;
}
public void setStunno3(String stunno3) {
this.stunno3 = stunno3;
}
public String getStunno4() {
return stunno4;
}
public void setStunno4(String stunno4) {
this.stunno4 = stunno4;
}
public int getHygienescore() {
return hygienescore;
}
public void setHygienescore(int hygienescore) {
this.hygienescore = hygienescore;
}
}

标签:System,get,renshu,equals,stu,println,第二次
From: https://www.cnblogs.com/ewqewq/p/16655499.html

相关文章