错误纠正
本次测试也算得上是对我假期学习的检验了,可能是我过于紧张了,最大的原因当然还是学得不太好,话不多说了,直接上代码吧!
就不显示成员变量和相关方法的.java文件了,只显示应用文件里面的代码啦!
学生公寓管理系统4
//RoomInformation.java
import java.util.ArrayList;
import java.util.Scanner;
public class RoomManagement {
//主界面
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<RoomInformation> arr = new ArrayList<RoomInformation>();
//存储10个宿舍信息
System.out.println("请根据提示录入10个宿舍信息:");
set(arr);
//编辑主界面
while (true) {
System.out.println("************************石家庄铁道大学");
System.out.println(" 学生公寓管理系统v2022");
System.out.println(" ***********************");
System.out.println(" 1、宿舍查询");
System.out.println(" 2、安排新宿舍");
System.out.println(" 3、调整宿舍");
System.out.println(" 4、宿舍卫生评价");
System.out.println(" 5、卫生检查情况查询");
System.out.println(" ***********************");
int c = sc.nextInt();
switch (c) {
case 1:
print(arr);
break;
case 2:
anPai(arr);
break;
case 3:
tiao(arr);
break;
case 4:
ping(arr);
break;
case 5:
recheck(arr);
break;
default:
System.out.println("该选项不存在!");
}
}
}
//记录10个宿舍信息
public static void set(ArrayList<RoomInformation> arr) {
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 3; i++) {
while (true) {
System.out.println("请输入你想要存储的宿舍号:");
String roomno = sc.nextLine();
int index = -1;
for (int j = 0; j < arr.size(); j++) {
RoomInformation ri = arr.get(j);
if (roomno.equals(ri.getRoomno())) {//宿舍号重复
index = j;
break;
}
}
if (index == -1) {//没有重复宿舍号
RoomInformation rr=new RoomInformation();
System.out.println("请确定该宿舍为什么状态的宿舍:1、空宿舍 2、已满 3、有空位");
String m = sc.nextLine();
switch (m) {
case "1"://空宿舍
rr.setRoomno(roomno);
rr.setStunno1(null);
rr.setStunno2(null);
rr.setStunno3(null);
rr.setStunno4(null);
arr.add(rr);
break;
case "2"://已满
System.out.println("请输入你想要存储的学号1:");
String x1 = sc.nextLine();
System.out.println("请输入你想要存储的学号2:");
String x2 = sc.nextLine();
System.out.println("请输入你想要存储的学号3:");
String x3 = sc.nextLine();
System.out.println("请输入你想要存储的学号4:");
String x4 = sc.nextLine();
rr.setRoomno(roomno);
rr.setStunno1(x1);
rr.setStunno2(x2);
rr.setStunno3(x3);
rr.setStunno4(x4);
arr.add(rr);
System.out.println("录入信息成功!");
break;
case "3"://有空位
System.out.println("请你选择有几个空位:");
String kk = sc.nextLine();
switch (kk) {
case "1":
System.out.println("请输入你想要存储的学号1:");
String y1 = sc.nextLine();
System.out.println("请输入你想要存储的学号2:");
String y2 = sc.nextLine();
System.out.println("请输入你想要存储的学号3:");
String y3 = sc.nextLine();
rr.setRoomno(roomno);
rr.setStunno1(y1);
rr.setStunno2(y2);
rr.setStunno3(y3);
rr.setStunno4(null);
arr.add(rr);
break;
case "2":
System.out.println("请输入你想要存储的学号1:");
String z1 = sc.nextLine();
System.out.println("请输入你想要存储的学号2:");
String z2 = sc.nextLine();
rr.setRoomno(roomno);
rr.setStunno1(z1);
rr.setStunno2(z2);
rr.setStunno3(null);
rr.setStunno4(null);
arr.add(rr);
break;
case "3":
System.out.println("请输入你想要存储的学号1:");
String p1 = sc.nextLine();
rr.setRoomno(roomno);
rr.setStunno1(p1);
rr.setStunno2(null);
rr.setStunno3(null);
rr.setStunno4(null);
arr.add(rr);
break;
}
break;
}
break;
}
else {
System.out.println("宿舍号重复!请重新输入宿舍号:");
}
}//while循环
}//录入宿舍信息
}
//宿舍查询
public static void print(ArrayList<RoomInformation> arr) {
System.out.println("************************石家庄铁道大学");
System.out.println(" 学生公寓管理系统v2022");
System.out.println(" ***********************");
System.out.println(" 宿舍详细信息列表");
//显示宿舍信息--遍历
for (int i = 0; i < arr.size(); i++) {
RoomInformation ri = arr.get(i);
System.out.print((i + 1) + "、" + ri.getRoomno() + " ");
if(ri.getStunno1()!=null&&ri.getStunno2()!=null&&ri.getStunno3()!=null&&ri.getStunno4()!=null){
System.out.println("4人 "+"已满");
}
else if((ri.getStunno1()!=null&&ri.getStunno2()!=null&&ri.getStunno3()!=null&&ri.getStunno4()==null)||(ri.getStunno1()!=null&&ri.getStunno2()!=null&&ri.getStunno3()==null&&ri.getStunno4()!=null)||
(ri.getStunno1()!=null&&ri.getStunno2()==null&&ri.getStunno3()!=null&&ri.getStunno4()!=null)||(ri.getStunno1()==null&&ri.getStunno2()!=null&&ri.getStunno3()!=null&&ri.getStunno4()!=null)){
System.out.println("3人 "+"空1人");
}
else if(ri.getStunno1()==null&&ri.getStunno2()==null&&ri.getStunno3()==null&&ri.getStunno4()==null){
System.out.println("0人 "+"空宿舍");
}
else if((ri.getStunno1()!=null&&ri.getStunno2()==null&&ri.getStunno3()==null&&ri.getStunno4()==null)||(ri.getStunno1()==null&&ri.getStunno2()!=null&&ri.getStunno3()==null&&ri.getStunno4()==null)||
(ri.getStunno1()==null&&ri.getStunno2()==null&&ri.getStunno3()!=null&&ri.getStunno4()==null)||(ri.getStunno1()==null&&ri.getStunno2()==null&&ri.getStunno3()==null&&ri.getStunno4()!=null)){
System.out.println("1人 "+"空3人");
}
else{
System.out.println("2人 "+"空2人");
}
}
System.out.println(" ***********************");
}
//安排新宿舍
public static void anPai(ArrayList<RoomInformation> arr){
Scanner sc=new Scanner(System.in);
System.out.println("************************石家庄铁道大学");
System.out.println(" 学生公寓管理系统v2022");
System.out.println(" 安排新宿舍");
System.out.println(" ***********************");
System.out.println(" 空宿舍详细信息列表");
//遍历出空的宿舍
for(int i=0;i<arr.size();i++){
RoomInformation ri=arr.get(i);
if(ri.getStunno1()==null&&ri.getStunno2()==null&&
ri.getStunno3()==null&&ri.getStunno4()==null){
System.out.println((i+1)+"、"+ri.getRoomno()+" 0人"+" 空宿舍");
}
}
System.out.println(" 请输入新宿舍号:");
System.out.println(" ***********************");
String roomno=sc.nextLine();
int index=-1;
for(int i=0;i<arr.size();i++){
RoomInformation ri=arr.get(i);
if(roomno.equals(ri.getRoomno())&&ri.getStunno1()==null&&ri.getStunno2()==null&&ri.getStunno3()==null&&ri.getStunno4()==null){//如果是空宿舍
index=i;
System.out.println("************************石家庄铁道大学");
System.out.println(" 学生公寓管理系统v2022");
System.out.println(" 安排新宿舍");
System.out.println(" ***********************");
System.out.println(" 新宿舍号:");
//遍历出该空宿舍信息
for(int j=0;j<4;j++){
System.out.println(" "+(i+1)+"、床位"+(i+1)+":"+"XXXXX(学号"+(i+1)+")");
}
System.out.println(" ***********************");
System.out.println("请依次输入四个床位所对应的学号:");
//学号判断
pan(arr);
break;
}
}
if(index==-1){
System.out.println("该宿舍不是空宿舍,无法安排新生");
}
}
//调整宿舍
public static void tiao(ArrayList<RoomInformation> arr){
Scanner sc=new Scanner(System.in);
System.out.println("************************石家庄铁道大学");
System.out.println(" 学生公寓管理系统v2022");
System.out.println(" ***********************");
System.out.println(" 有空床位宿舍详细信息列表");
int m=0;
for (int i = 0; i < arr.size(); i++) {
RoomInformation ri = arr.get(i);
if (!(ri.getStunno1() != null && ri.getStunno2() != null && ri.getStunno3() != null && ri.getStunno4() != null) && !(ri.getStunno1() == null && ri.getStunno2() == null && ri.getStunno3() == null && ri.getStunno4() == null)&&ri.getRoomno()!=null) {
System.out.print((++m) + "、" + ri.getRoomno() + " ");
if ((ri.getStunno1() != null && ri.getStunno2() != null && ri.getStunno3() != null && ri.getStunno4() == null) || (ri.getStunno1() != null && ri.getStunno2() != null && ri.getStunno3() == null && ri.getStunno4() != null) ||
(ri.getStunno1() != null && ri.getStunno2() == null && ri.getStunno3() != null && ri.getStunno4() != null) || (ri.getStunno1() == null && ri.getStunno2() != null && ri.getStunno3() != null && ri.getStunno4() != null)) {
System.out.println("3人 " + "空1人");
} else if ((ri.getStunno1() != null && ri.getStunno2() == null && ri.getStunno3() == null && ri.getStunno4() == null) || (ri.getStunno1() == null && ri.getStunno2() != null && ri.getStunno3() == null && ri.getStunno4() == null) ||
(ri.getStunno1() == null && ri.getStunno2() == null && ri.getStunno3() != null && ri.getStunno4() == null) || (ri.getStunno1() == null && ri.getStunno2() == null && ri.getStunno3() == null && ri.getStunno4() != null)) {
System.out.println("1人 " + "空3人");
} else {
System.out.println("2人" + " 空2人");
}
}//if语句
}
System.out.println(" 请输入待调整宿舍号:");
String number=sc.nextLine();
System.out.println(" ***********************");
for(int i=0;i<arr.size();i++){
RoomInformation ri=arr.get(i);
if(number.equals(ri.getRoomno())&&((ri.getStunno1()!=null&&ri.getStunno2()!=null&&ri.getStunno3()!=null&&ri.getStunno4()!=null)||(ri.getStunno1()==null&&ri.getStunno2()==null&&ri.getStunno3()==null&&ri.getStunno4()==null))){
System.out.println("该宿舍没有空床位,无法调整");
break;
}
}
}
//学号判断
public static void pan(ArrayList<RoomInformation> arr){
Scanner sc=new Scanner(System.in);
for(int j=0;j<4;j++) {
while(true) {
System.out.println("请输入相应学号:");
String id = sc.nextLine();
int index = -1;
for (int i = 0; i < arr.size(); i++) {
RoomInformation ri = arr.get(i);
if (id.equals(ri.getStunno1()) || id.equals(ri.getStunno2()) || id.equals(ri.getStunno3())
|| id.equals(ri.getStunno4())) {
index = i;
break;
}
}
if (index == -1) {
RoomInformation ri = new RoomInformation();
if (j == 0) {
ri.setStunno1(id);
arr.add(ri);
}
if (j == 1) {
ri.setStunno2(id);
arr.add(ri);
}
if (j == 2) {
ri.setStunno3(id);
arr.add(ri);
}
if (j == 3) {
ri.setStunno4(id);
arr.add(ri);
}
break;
} else {
System.out.println("学号重复!请重新输入该学号:");
}
}
}
System.out.println("该宿舍已满!");
}
//宿舍卫生评价
public static void ping(ArrayList<RoomInformation> arr){
Scanner sc=new Scanner(System.in);
while(true) {
int index=-1;
System.out.println("************************石家庄铁道大学");
System.out.println(" 学生公寓管理系统v2022");
System.out.println(" 宿舍卫生评价");
System.out.println(" ***********************");
System.out.println(" 请输入待评价宿舍号:");
System.out.println(" ***********************");
String roomno = sc.nextLine();
for (int i = 0; i < arr.size(); i++) {
RoomInformation ri = arr.get(i);
if (!(ri.getStunno1() == null && ri.getStunno2() == null && ri.getStunno3() == null && ri.getStunno4() == null)&&roomno.equals(ri.getRoomno())) {//非空
index = i;
while (true) {
System.out.println("************************石家庄铁道大学");
System.out.println(" 学生公寓管理系统v2022");
System.out.println(" 宿舍卫生评价");
System.out.println(" ***********************");
System.out.println(" 宿舍号:" + ri.getRoomno());
System.out.println(" 1、床位1:" + ri.getStunno1());
System.out.println(" 2、床位2:" + ri.getStunno2());
System.out.println(" 3、床位3:" + ri.getStunno3());
System.out.println(" 4、床位4:" + ri.getStunno4());
System.out.println(" 输入宿舍卫生评价分数:");
System.out.println(" ***********************");
int hyg = sc.nextInt();
if (hyg < 0 || hyg > 100) {
System.out.println("输入错误");//重新输入
} else {
ri.setHygienescore(hyg);
break;
}
}
break;
}
}
if(index==-1){//是空宿舍
System.out.println("该宿舍为空宿舍");
break;
}
else{
break;
}
}
}
//卫生检查状况查询
public static void recheck(ArrayList<RoomInformation> arr){
System.out.println("************************石家庄铁道大学");
System.out.println(" 学生公寓管理系统v2022");
System.out.println(" 卫生检查情况查询");
System.out.println(" ***********************");
System.out.println(" 宿舍卫生检查情况信息");
int m=0;
for(int i=0;i<arr.size();i++){
RoomInformation ri=arr.get(i);
if(!(ri.getStunno1()==null&&ri.getStunno2()==null&&ri.getStunno3()==null&&ri.getStunno4()==null)&&ri.getRoomno()!=null){//非空宿舍
System.out.print((++m)+"、"+ri.getRoomno()+" "+ri.getHygienescore()+" ");
if(ri.getHygienescore()<60){
System.out.println("不合格");
}
else if(ri.getHygienescore()>=60&&ri.getHygienescore()<90){
System.out.println("合格");
}
else{
System.out.println("优秀");
}
}
}
System.out.println(" ***********************");
}
}
标签:纠正,&&,错误,System,测试,println,null,ri,out
From: https://www.cnblogs.com/liuzijin/p/16649604.html