首页 > 编程语言 >2022年java第一次随堂测试

2022年java第一次随堂测试

时间:2022-09-02 21:34:29浏览次数:56  
标签:cnt java String 随堂 System rf 2022 print out

//源代码

import java.util.Scanner;

public class RoomManagement {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
RoomInformation r1 = new RoomInformation("9#401", "20214001", "20214002", "20214003", "20214004", 0);
RoomInformation r2 = new RoomInformation("9#402", "", "", "", "", 0);
RoomInformation r3 = new RoomInformation("9#403", "", "", "", "", 0);
RoomInformation r4 = new RoomInformation("9#404", "", "", "", "", 0);
RoomInformation r5 = new RoomInformation("9#405", "", "20214011", "20214012", "20214013", 0);
RoomInformation r6 = new RoomInformation("9#406", "20214021", "", "20214022", "20214023", 0);
RoomInformation r7 = new RoomInformation("9#407", "20214031", "20214032", "", "20214033", 0);
RoomInformation r8 = new RoomInformation("9#408", "20214041", "20214042", "20214043", "20214044", 0);
RoomInformation r9 = new RoomInformation("9#409", "20214051", "20214052", "20214053", "20214054", 0);
RoomInformation r10 = new RoomInformation("9#410", "20214061", "20214062", "20214063", "20214064", 0);
rf[1] = r1;
rf[2] = r2;
rf[3] = r3;
rf[4] = r4;
rf[5] = r5;
rf[6] = r6;
rf[7] = r7;
rf[8] = r8;
rf[9] = r9;
rf[10] = r10;
menu1();
}
static RoomInformation rf[] = new RoomInformation[1010];
static int cnt = 10;
public static void menu() {
System.out.println("***********************************************************");
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("**********************************************************");
}

public static void menu1() {
int n = 0;
while (n != 5) {
Scanner sc = new Scanner(System.in);
menu();
n = sc.nextInt();
if (n == 1)
chaxun();
else if (n == 2)
anpai();
else if (n == 3)
tiaozheng();
else if (n == 4)
weishengpingjia();
else if (n == 5)
weishengchaxun();
else {
System.out.println("该选项不存在");
menu();
}
}
}

public static void chaxun() {
System.out.print("***********************************************************\n"
+ " 石家庄铁道大学\r\n"
+ " 学生公寓管理系统v2022\r\n"
+ "***********************************************************\r\n"
+ "");
for (int i = 1; i <= cnt; i++) {
int no_cnt = 0;//统计人数
System.out.print(i + "、" + rf[i].getRoomno() + "\t");
if (rf[i].getStunno1() != "")
no_cnt++;
if (rf[i].getStunno2() != "")
no_cnt++;
if (rf[i].getStunno3() != "")
no_cnt++;
if (rf[i].getStunno4() != "")
no_cnt++;
if (no_cnt == 4) {
System.out.print(no_cnt + "人" + "\t");
System.out.print("已满\n");
}
else if (no_cnt == 3) {
System.out.print(no_cnt + "人" + "\t");
System.out.print("空1人\n");
}
else if (no_cnt == 2) {
System.out.print(no_cnt + "人" + "\t");
System.out.print("空2人\n");
}
else if (no_cnt == 1) {
System.out.print(no_cnt + "人" + "\t");
System.out.print("空3人\n");
}
else if (no_cnt == 0) {
System.out.print(no_cnt + "人" + "\t");
System.out.print("空宿舍\n");
}
}
}

public static int anpaipanduan(String no0) {
if (no0.equals("END")) {
return 3;
}
for(int i = 1; i <= cnt; i++) {
if (no0.equals(rf[i].getStunno1()) || no0.equals(rf[i].getStunno2()) || no0.equals(rf[i].getStunno3()) || no0.equals(rf[i].getStunno4())) {
System.out.print("该学生已分配宿舍\n");
return 2;
}
}
return 1;
}

public static void anpaijiemian() {
Scanner sc = new Scanner(System.in);
System.out.print("***********************************************************\n"
+ " 石家庄铁道大学\r\n"
+ " 学生公寓管理系统v2022\r\n"
+ " 安排新宿舍\r\n"
+ "***********************************************************\r\n"
+ " 新宿舍号:\r\n"
+ "");
System.out.print("1、床位1:");
String no1 = sc.next();
if (anpaipanduan(no1) == 2) {
no1 = sc.next();
}
else if (anpaipanduan(no1) == 3) {
cnt ++;
menu();
}
System.out.print("\n");
System.out.print("2、床位2:");
String no2 = sc.next();
if (anpaipanduan(no2) == 2) {
no2 = sc.next();
}
else if (anpaipanduan(no2) == 3) {
cnt ++;
menu();
}
System.out.print("\n");
System.out.print("3、床位3:");
String no3 = sc.next();
if (anpaipanduan(no3) == 2) {
no3 = sc.next();
}
else if (anpaipanduan(no3) == 3) {
cnt ++;
menu();
}
System.out.print("\n");
System.out.print("4、床位4:");
String no4 = sc.next();
System.out.print("***********************************************************\n");
if (anpaipanduan(no4) == 2) {
no4 = sc.next();
}
else if (anpaipanduan(no4) == 3 || anpaipanduan(no4) == 1) {
System.out.print("\n");
System.out.print("提示该宿舍已满\n");
cnt ++;
menu();
}

}

public static void anpai() {
Scanner sc = new Scanner(System.in);
System.out.print("***********************************************************\n"
+ " 石家庄铁道大学\r\n"
+ " 学生公寓管理系统v2022\r\n"
+ " 安排新宿舍\r\n"
+ "***********************************************************\r\n"
+ "");
System.out.print(" 空宿舍详细信息列表\n");
for (int i = 1; i <= cnt; i++) {
if (rf[i].getStunno1() == "" && rf[i].getStunno2() == "" && rf[i].getStunno3() == "" && rf[i].getStunno4() == "") {
System.out.print(i + "、" + rf[i].getRoomno() + "\t\t" + "0人\t空宿舍\n");
}
}
System.out.print(" 请输入新宿舍号:");
String new_roomno = sc.next();
System.out.print("***********************************************************\n");
for (int i = 1; i <= cnt; i++) {
if(new_roomno.equals(rf[i].getRoomno())) {
if (rf[i].getStunno1() == "" && rf[i].getStunno2() == "" && rf[i].getStunno3() == "" && rf[i].getStunno4() == "") {
anpaijiemian();
}
else {
System.out.print("该宿舍不是空宿舍,无法安排新生\n");
}
}
}
}

public static void tiaozhengjiemian() {
Scanner sc = new Scanner(System.in);
System.out.print("***********************************************************\n"
+ " 石家庄铁道大学\r\n"
+ " 学生公寓管理系统v2022\r\n"
+ " 调整宿舍\r\n"
+ "***********************************************************\r\n"
+ " 有空床位宿舍详细信息列表\r\n"
+ "");
for (int i = 1; i <= cnt; i++) {
int no_cnt = 0;//统计人数
System.out.print(i + "、" + rf[i].getRoomno() + "\t");
if (rf[i].getStunno1() != "")
no_cnt++;
if (rf[i].getStunno2() != "")
no_cnt++;
if (rf[i].getStunno3() != "")
no_cnt++;
if (rf[i].getStunno4() != "")
no_cnt++;
if (no_cnt == 3) {
System.out.print(no_cnt + "人" + "\t");
System.out.print("空1人\n");
}
else if (no_cnt == 2) {
System.out.print(no_cnt + "人" + "\t");
System.out.print("空2人\n");
}
else if (no_cnt == 1) {
System.out.print(no_cnt + "人" + "\t");
System.out.print("空3人\n");
}
}
System.out.print("请输入待调整宿舍号:");
}

public static void tiaozhengjiemian2(String roomno) {
System.out.print("***********************************************************\n"
+ "石家庄铁道大学\r\n"
+ "学生公寓管理系统v2022\r\n"
+ "调整宿舍\r\n"
+ "***********************************************************\r\n"
+ "待调整宿舍号:"
+ roomno
+ "");
}



public static void tiaozheng() {
Scanner sc = new Scanner(System.in);
tiaozhengjiemian();
String new_roomno = sc.next();
System.out.print("***********************************************************\n");
for (int i = 1; i <= cnt; i++) {
if (new_roomno.equals(rf[i].getRoomno())) {
if (rf[i].getStunno1() == "" || rf[i].getStunno2() == "" || rf[i].getStunno3() == "" || rf[i].getStunno4() == "") {
tiaozhengjiemian2(new_roomno);
System.out.print("1、床位1:");
System.out.print(rf[i].getStunno1());
System.out.print("2、床位2:");
System.out.print(rf[i].getStunno2());
System.out.print("3、床位3:");
System.out.print(rf[i].getStunno3());
System.out.print("4、床位4:");
String stuno = sc.next();
if (anpaipanduan(stuno) == 3) {
menu();
}
else if (anpaipanduan(stuno) == 2) {
tiaozhengjiemian2(new_roomno);
}
else {
System.out.print("提示该宿舍已满");
menu();
}

}
else if (rf[i].getStunno1() != "" && rf[i].getStunno2() != "" && rf[i].getStunno3() != "" && rf[i].getStunno4() != "") {
System.out.print("该宿舍没有空床位,无法调整");
}
}
}
}

public static void wsjm() {
System.out.print("***********************************************************\n"
+ "石家庄铁道大学\r\n"
+ "学生公寓管理系统v2022\r\n"
+ "宿舍卫生\r\n"
+ "***********************************************************\r\n"
+ "");
System.out.print("请输入待评价宿舍号:");
}

public static void weishengpingjia() {
Scanner sc = new Scanner(System.in);
System.out.print("***********************************************************\n"
+ "石家庄铁道大学\r\n"
+ "学生公寓管理系统v2022\r\n"
+ "宿舍卫生\r\n"
+ "***********************************************************\r\n"
+ "");
System.out.print("请输入待评价宿舍号:");
String roomno = sc.next();
for (int i = 1; i <= cnt; i++) {
if (roomno.equals(rf[i].getRoomno())) {
if (rf[i].getStunno1() == "" && rf[i].getStunno2() == "" && rf[i].getStunno3() == "" && rf[i].getStunno4() == "") {
System.out.print("该宿舍为空宿舍");
weishengpingjia();
}
else {
System.out.print("***********************************************************\n"
+ "石家庄铁道大学\r\n"
+ "学生公寓管理系统v2022\r\n"
+ "宿舍卫生评价\r\n"
+ "***********************************************************\r\n"
+ "宿舍号:\r\n"
+ "");
System.out.print(roomno);
System.out.print("1、床位1:");
System.out.print(rf[i].getStunno1());
System.out.print("2、床位2:");
System.out.print(rf[i].getStunno2());
System.out.print("3、床位3:");
System.out.print(rf[i].getStunno3());
System.out.print("4、床位4:");
System.out.print(rf[i].getStunno4());

System.out.print("输入宿舍卫生评价分数:");
int wsscore = 0;
while (true) {
wsscore = sc.nextInt();
if (wsscore >=0 && wsscore <= 100) {
break;
}
else {
System.out.print("输入错误");
}

}
System.out.print("***********************************************************\n");
}
}
}
System.out.print("***********************************************************\n");
}

public static void weishengchaxun() {
System.out.print("***********************************************************\n"
+ "石家庄铁道大学\r\n"
+ "学生公寓管理系统v2022\r\n"
+ "卫生检查情况查询\r\n"
+ "***********************************************************\r\n"
+ "宿舍卫生检查情况信息\r\n"
+ "");
for (int i = 1; i <= cnt; i++) {
System.out.print(rf[i].getRoomno() + "\t" + rf[i].getHygienescore());
if (rf[i].getHygienescore() < 60)
System.out.print("不合格");
else if (rf[i].getHygienescore() >= 60 && rf[i].getHygienescore() < 80)
System.out.print("合格");
else if (rf[i].getHygienescore() >= 80 && rf[i].getHygienescore() < 90)
System.out.print("良好");
else if (rf[i].getHygienescore() >= 90)
System.out.print("优秀");
}
}

}

class RoomInformation {
private String roomno;// 8位 eg:9#502
private String stunno1, stunno2, stunno3, stunno4;
// 8位 空表示无数值,代表空余床位,
// 都空表示空宿舍
private int hygienescore;// 0-100 卫生标准分
// <60 不合格;>=60 合格;>=80 良好;>=90 优秀

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;
}

public RoomInformation(String roomno, String stunno1, String stunno2, String stunno3, String stunno4,
int hygienescore) {
this.roomno = roomno;
this.stunno1 = stunno1;
this.stunno2 = stunno2;
this.stunno3 = stunno3;
this.stunno4 = stunno4;
this.hygienescore = hygienescore;
}

public RoomInformation(RoomInformation r0) {
this.roomno = r0.roomno;
this.stunno1 = r0.stunno1;
this.stunno2 = r0.stunno2;
this.stunno3 = r0.stunno3;
this.stunno4 = r0.stunno4;
this.hygienescore = r0.hygienescore;
}

}

标签:cnt,java,String,随堂,System,rf,2022,print,out
From: https://www.cnblogs.com/sodamate/p/16651283.html

相关文章

  • CSP_202206-2_寻宝!大冒险!
    CSP_202206-2_寻宝!大冒险题目链接思路相当于判断两个有限集合AB之间是不是满射和单射,只需要保证以下两点A和B元素个数相等A中每个元素都能通过映射\(\psi\)到B中一个......
  • 2022-09-02 第四组 王佳齐 学习笔记
    coolie:保存http状态,保存在客户端,保存在浏览器上的;登录信息,保存在浏览器上,以键值对的形式,不安全。使用cookie的流程:1.创建Cookie对象2.设置最大时效3.把cookie放到Ht......
  • 2022-9-2 cookie 和 session
    会话技术会话:一次会话中包含多次请求和响应。一次会话:浏览器第一次给服务器资源发送请求,会话建立,直到有一方断开为止功能:在一次会话的范围内的多次请求间,共享数据......
  • 2022-2023-1 20221424《计算机基础与程序设计》第一周学习总结
    学期:2022-2023-1学号:20221424《计算机基础与程序设计》第1周学习总结作业信息班级:https://edu.cnblogs.com/campus/besti/2022-2023-1-CFAP作业要求:https://www.cnb......
  • Java中this和super的用法总结
    原文:https://www.cnblogs.com/hasse/p/5023392.htmlthis指向对象本身的指针,形参与成员名字重名,用this来区分。super超(父)类对象的一个指针。一、thisthis是自身......
  • 「NOI2022」冒泡排序
    题目给定正整数\(n\)和\(m\)条限制,每条限制为非负整数三元组\((L,R,V)\)。现在,你需要构造一个长度为\(n\)的非负整数序列,并且满足每一条限制:一条限制\((L,R,V)\)......
  • Java 并发编程解析 | 如何正确理解Java领域中的锁机制,我们一般需要掌握哪些理论知识?
    苍穹之边,浩瀚之挚,眰恦之美;悟心悟性,善始善终,惟善惟道!——朝槿《朝槿兮年说》写在开头提起Java领域中的锁,是否有种“道不尽红尘奢恋,诉不完人间恩怨“的”感同身受“......
  • Android学习笔记八(JAVA):数据库与Room持久性库,菜单栏,数据绑定
    本篇笔记实现如下所示的功能。在NoteListFragment页面增加了菜单栏,菜单栏中有NewNote选项,点击它跳转到新建Note页面。输入TITLE和CONTENT后,点击CREATE按钮,会在数据库中添......
  • Intellij IDEA 'Error:java: 无效的源发行版:13'
      原文链接:https://blog.csdn.net/liuqiker/article/details/101528205  1,首先亮一下我的IDEA版本:2,我遇上的问题:3,我怎么解决的?1,首先亮一下我的IDEA版本(官网下载......
  • java 内存模型之 volatile 核心原理与应用
    1.happens-before规则https://blog.csdn.net/qq_39935047/article/details/1203847992.Juc12_Volatile的可见性、不保证可见性、有序性、使用、内存屏障四大指令StoreSt......