java开学第一节课,我们亲爱的建民老师给我们准备了一套题目,在暑假时我们已经自学了一部分内容,但是突如其来的考试还是让我乱了阵脚,主要是熟练度不高,只完成了一些基础的项目,后面的项目没来得及写,最后成绩是9.5分,不到及格线。在那之后,我好好的研究了这一个题目,最后把所有要求完成了。以下是我的代码。
package work; class RoomInformation { private String roomno,stunno1,stunno2,stunno3,stunno4; private int hygienescore=0; 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 void setRoomno(String r) {roomno=r;} public String getRoomon() {return roomno;} public void setStunno1(String s) {stunno1=s;} public String getStunno1() {return stunno1;} public void setStunno2(String s) {stunno2=s;} public String getStunno2() {return stunno2;} public void setStunno3(String s) {stunno3=s;} public String getStunno3() {return stunno3;} public void setStunno4(String s) {stunno4=s;} public String getStunno4() {return stunno4;} public void setHygienescore(int h) {hygienescore=h;} public int getHygienescore() {return hygienescore;} }
package work; import java.util.*; public class RoomManagement { static Scanner sc=new Scanner(System.in); static ArrayList<RoomInformation> list=new ArrayList<RoomInformation>(); public static void main(String[] args) { list.add(new RoomInformation("9#101","20210001","20210002", "20210003", "20210004",0)); list.add(new RoomInformation("9#102","20210011","20210012", "20210013", "20210014",0)); list.add(new RoomInformation("9#103","20210021","20210022", "20210023", "",0)); list.add(new RoomInformation("9#104","20210031","20210032", "20210033", "", 0)); list.add(new RoomInformation("9#105","20210041","", "", "",0)); list.add(new RoomInformation("9#106","20210051","20210052", "20210053", "20210054",0)); list.add(new RoomInformation("9#107","","", "", "",0)); list.add(new RoomInformation("9#108","","", "", "",0)); list.add(new RoomInformation("9#109","","", "", "",0)); list.add(new RoomInformation("9#110","","", "", "",0)); while(true) { showTopic(); System.out.println("\t\t1、宿舍查询"); System.out.println("\t\t2、安排新宿舍"); System.out.println("\t\t3、调整宿舍"); System.out.println("\t\t4、宿舍卫生评价"); System.out.println("\t\t5、卫生检查情况查询"); System.out.println("**********************************************************"); int a=sc.nextInt(); if(a==1) { chaxun(); } else if(a==2) { anpai(); } else if(a==3) { tiaozheng(); } else if(a==4) { weisheng(); } else if(a==5) { pinjia(); } else { System.out.println("查无此项,请重新输入"); } } } static void showTopic() { System.out.println("***********************************************************"); System.out.println("\t\t石家庄铁道大学"); System.out.println("\t\t学生公寓管理系统v2022"); System.out.println("***********************************************************"); } static void chaxun() { showTopic(); System.out.println("\t\t宿舍详细信息列表"); for(int i=0;i<list.size();i++) { int renshu = 0; if (list.get(i).getStunno1() != "") renshu++; if (list.get(i).getStunno2() != "") renshu++; if (list.get(i).getStunno3() != "") renshu++; if (list.get(i).getStunno4() != "") renshu++; System.out.print("\t\t"+(i+1)+"、"+list.get(i).getRoomon()); if(renshu==4) { System.out.println(" "+"4人"+" 已满"); } else if(renshu!=4&&renshu!=0) { System.out.println(" "+renshu+"人"+" 空"+(4-renshu)+"人"); } else if(renshu==0) { System.out.println(" "+"0人"+" 空宿舍"); } } System.out.println("***********************************************************"); } static void anpai() { showTopic(); System.out.println("\t\t安排新宿舍"); System.out.println("\t\t空宿舍详细信息列表"); int num=1; for(int i=0;i<list.size();i++) { if(list.get(i).getStunno1()==""&&list.get(i).getStunno2()==""&&list.get(i).getStunno3()==""&&list.get(i).getStunno4()=="") { System.out.println("\t\t"+num+"、"+list.get(i).getRoomon()+" "+"0人"+" 空宿舍"); num++; } } System.out.println("***********************************************************"); System.out.println("\t\t请输入新宿舍号:"); String b=sc.next(); int flag=-1; for(int i=0;i<list.size();i++) { if(list.get(i).getRoomon().equals(b)) { flag=i; break; } } if(flag==-1){ System.out.println("\t\t宿舍号不存在"); anpai(); } if(list.get(flag).getStunno1().equals("")&&list.get(flag).getStunno2().equals("")&&list.get(flag).getStunno3().equals("")&&list.get(flag).getStunno4().equals("")) { while(true) { showTopic(); System.out.println("\t\t安排新宿舍"); System.out.println("\t\t新宿舍号:"+list.get(flag).getRoomon()); String flag1,flag2,flag3,flag4; int n=1; if(list.get(flag).getStunno1().equals("")) { System.out.print("1、床位1:"); flag1=sc.next(); if(flag1.equals("END")) { break; } for(int i=0;i<list.size();i++) { if(list.get(i).getStunno1().equals(flag1)||list.get(i).getStunno2().equals(flag1)||list.get(i).getStunno3().equals(flag1)||list.get(i).getStunno4().equals(flag1)) { n=0; } } if(n==0) { System.out.println("该学生已分配宿舍"); continue; } list.get(flag).setStunno1(flag1); } if(list.get(flag).getStunno2().equals("")) { System.out.print("2、床位2:"); flag2=sc.next(); if(flag2.equals("END")) { break; } for(int i=0;i<list.size();i++) { if(list.get(i).getStunno1().equals(flag2)||list.get(i).getStunno2().equals(flag2)||list.get(i).getStunno3().equals(flag2)||list.get(i).getStunno4().equals(flag2)) { n=0; } } if(n==0) { System.out.println("该学生已分配宿舍"); continue; } list.get(flag).setStunno2(flag2); } if(list.get(flag).getStunno3().equals("")) { System.out.print("3、床位3:"); flag3=sc.next(); if(flag3.equals("END")) { break; } for(int i=0;i<list.size();i++) { if(list.get(i).getStunno1().equals(flag3)||list.get(i).getStunno2().equals(flag3)||list.get(i).getStunno3().equals(flag3)||list.get(i).getStunno4().equals(flag3)) { n=0; } } if(n==0) { System.out.println("该学生已分配宿舍"); continue; } list.get(flag).setStunno3(flag3); } System.out.print("4、床位4:"); flag4=sc.next(); if(flag4.equals("END")) { break; } for(int i=0;i<list.size();i++) { if(list.get(i).getStunno1().equals(flag4)||list.get(i).getStunno2().equals(flag4)||list.get(i).getStunno3().equals(flag4)||list.get(i).getStunno4().equals(flag4)) { n=1; } } if(n==0) { System.out.println("该学生已分配宿舍"); continue; } else { list.get(flag).setStunno4(flag4); System.out.println("该宿舍已满"); break; } } } else { System.out.println("\t\t该宿舍不是空宿舍,无法安排新生"); anpai(); } } static void tiaozheng() { showTopic(); System.out.println("\t\t调整宿舍"); int num=1; for(int i=0;i<list.size();i++) { int renshu = 0; if (list.get(i).getStunno1() != "") renshu++; if (list.get(i).getStunno2() != "") renshu++; if (list.get(i).getStunno3() != "") renshu++; if (list.get(i).getStunno4() != "") renshu++; if(renshu<4) { System.out.print("\t\t"+num+"、"+list.get(i).getRoomon()); System.out.println(" "+renshu+"人 空"+(4-renshu)+"人"); num++; } } System.out.println("\t\t请输入待调整的宿舍号:"); System.out.println("***********************************************************"); String a=sc.next(); int flag=-1; for(int i=0;i<list.size();i++) { if(list.get(i).getRoomon().equals(a)) { flag=i; } } if(flag==-1) { System.out.println("\t\t宿舍不存在"); } if(list.get(flag).getStunno1().equals("")||list.get(flag).getStunno2().equals("")||list.get(flag).getStunno3().equals("")||list.get(flag).getStunno4().equals("")) { while(true) { showTopic(); System.out.println("\t\t调整宿舍"); System.out.println("\t\t待调整宿舍号:"+a); String flag1,flag2,flag3,flag4; int n=1; if(list.get(flag).getStunno1().equals("")) { System.out.println("\t\t1、床位1"); flag1=sc.next(); if(flag1.equals("END")) { break; } for(int i=0;i<list.size();i++) { if(list.get(i).getStunno1().equals(flag1)||list.get(i).getStunno2().equals(flag1)||list.get(i).getStunno3().equals(flag1)||list.get(i).getStunno4().equals(flag1)) { n=0; } } if(n==0) { System.out.println("该学生已分配宿舍"); continue; } list.get(flag).setStunno1(flag1); } if(list.get(flag).getStunno2().equals("")) { System.out.println("\t\t2、床位2"); flag2=sc.next(); if(flag2.equals("END")) { break; } for(int i=0;i<list.size();i++) { if(list.get(i).getStunno1().equals(flag2)||list.get(i).getStunno2().equals(flag2)||list.get(i).getStunno3().equals(flag2)||list.get(i).getStunno4().equals(flag2)) { n=0; } } if(n==0) { System.out.println("该学生已分配宿舍"); continue; } list.get(flag).setStunno1(flag2); } if(list.get(flag).getStunno3().equals("")) { System.out.println("\t\t3、床位3"); flag3=sc.next(); if(flag3.equals("END")) { break; } for(int i=0;i<list.size();i++) { if(list.get(i).getStunno1().equals(flag3)||list.get(i).getStunno2().equals(flag3)||list.get(i).getStunno3().equals(flag3)||list.get(i).getStunno4().equals(flag3)) { n=0; } } if(n==0) { System.out.println("该学生已分配宿舍"); continue; } list.get(flag).setStunno1(flag3); } System.out.println("\t\t4、床位4"); flag4=sc.next(); if(flag4.equals("END")) { break; } for(int i=0;i<list.size();i++) { if(list.get(i).getStunno1().equals(flag4)||list.get(i).getStunno2().equals(flag4)||list.get(i).getStunno3().equals(flag4)||list.get(i).getStunno4().equals(flag4)) { n=0; } } if(n==0) { System.out.println("该学生已分配宿舍"); continue; } else { list.get(flag).setStunno1(flag4); System.out.println("该宿舍已满"); break; } } } else { System.out.println("该宿舍没有空床位"); tiaozheng(); } } static void weisheng() { showTopic(); System.out.println("\t\t宿舍卫生"); System.out.println("\t\t请输入宿舍号:"); String flag=sc.next(); for(int i=0;i<list.size();i++) { if(list.get(i).getRoomon().equals(flag)) { if(list.get(i).getStunno1()==""&&list.get(i).getStunno2()==""&&list.get(i).getStunno3()==""&&list.get(i).getStunno4()=="") { System.out.println("该寝室是空寝室"); weisheng(); } else { showTopic(); System.out.println("\t\t宿舍卫生评价"); System.out.print("\t\t宿舍号:"); System.out.println(list.get(i).getRoomon()); System.out.print("\t\t1、床位1:"); System.out.println(list.get(i).getStunno1()); System.out.print("\t\t2、床位2:"); System.out.println(list.get(i).getStunno2()); System.out.print("\t\t3、床位3:"); System.out.println(list.get(i).getStunno3()); System.out.print("\t\t4、床位4:"); System.out.println(list.get(i).getStunno4()); System.out.print("输入宿舍卫生评价分数:"); int score; while(true) { score=sc.nextInt(); if(score>=0&&score<=100) { list.get(i).setHygienescore(score); System.out.println("已录入"); break; } else { System.out.print("输入错误"); } } } } } } static void pinjia() { showTopic(); System.out.println("\t\t卫生检查情况查询"); for(int i=0;i<list.size();i++) { System.out.print("\t\t"+(i+1)+"、"+list.get(i).getRoomon()+" "+list.get(i).getHygienescore()); if(list.get(i).getHygienescore()<60) { System.out.println(" "+"不合格"); } else if(list.get(i).getHygienescore()<80&&list.get(i).getHygienescore()>=60) { System.out.println(" "+"合格"); } else if(list.get(i).getHygienescore()>=80&&list.get(i).getHygienescore()<90) { System.out.println(" "+"良好"); } else if(list.get(i).getHygienescore()>=90&&list.get(i).getHygienescore()<=100) { System.out.println(" "+"优秀"); } } } }
标签:开学,String,list,System,铁道,2022,println,public,out From: https://www.cnblogs.com/liurujun/p/16881416.html