编程语言
首页 > 编程语言> > Java开学考试感想及代码

Java开学考试感想及代码

作者:互联网

本次开学考试是对Java基础的考察,做的是一个公寓宿舍管理系统,比上届的论文查重系统简单的多,但结果却差强人意,

在家中的学习和练习还不够,导致编程的时候题目的功能并不能实现,最后导致编程的结果不尽人意。

最后在学习Java的过程中我得出这样的结论:

1.学习中,要养成良好的习惯(写括号时要成对,字母大小写要区分,单词拼写要准确)。

2.在学习的过程中,最好不是仅仅停留在java表层,不是抄书上的例子运行出结果就可以。要注意,即便对一个简单的例子也要有耐心去琢磨、调试、改动。

3.在学习的过程中一定要动手做、试着写代码,而不是抱一本书看看就行。很多东西和体会必须自己动手才能真正属于自己。

4. 在 Java 的学习过程中,可能会遇到形形色色的问题不容易解决,应多去专业论坛了解相关的知识,书本上的知识有限。要会从网上搜索有用的信息 加以整理,促进学习的深入和知识水平的提高。

看了好多网上课程,说学到一定程度要尝试着自己做东西,但觉得自己仅仅经过一学期的学习,还远远不够,希望自己在以后学习中继续努力,能够真真正正拥有一门编程语言,对自己今后的发展起到作用。在学习java语言的同时,也让我学会了如何来发现问题,如何解决问题,怎样有效的学习等等,相信会对我一生都有帮助。

package test;

public class RoomInformation {
     private String roomno;
     private String stunno1;
     private String stunno2;
     private String stunno3;
     private String stunno4;
     private int 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;
	}
	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;
	}
     
}

  

package test;

import java.util.Scanner;

public class RoomManagement {
      static Scanner sc=null;
      static RoomInformation[] s = new RoomInformation[10];
	
      public static void main(String[] args) {
    	  sc=new Scanner(System.in);
    	RoomInformation s0 = new RoomInformation("9#101","20213000","20213001","20213002","20213003",0);
    	RoomInformation s1 = new RoomInformation("9#102","20213100","20213101","20213102","20213103",0);
    	RoomInformation s2 = new RoomInformation("9#103","20213200","20213201","20213202","",0);
    	RoomInformation s3 = new RoomInformation("9#104","20213300","","","",0);
    	RoomInformation s4 = new RoomInformation("9#105","20213400","20213401","","",0);
    	RoomInformation s5 = new RoomInformation("9#106","20213500","20213501","20213502","20213503",0);
    	RoomInformation s6 = new RoomInformation("9#107","20213600","20213601","20213602","20213603",0);
    	RoomInformation s7 = new RoomInformation("9#108","","","","",0);
    	RoomInformation s8 = new RoomInformation("9#109","","","","",0);
    	RoomInformation s9 = new RoomInformation("9#110","","","","",0);
    	s[0]=s0;
    	s[1]=s1;
    	s[2]=s2;
    	s[3]=s3;
    	s[4]=s4;
    	s[5]=s5;
    	s[6]=s6;
    	s[7]=s7;
    	s[8]=s8;
    	s[9]=s9;
    	while(true) {
    	show();
    	System.out.println("请输入你的选择:");
    	int a=sc.nextInt();
    	if(a>6||a<1) {
    		System.out.println("该选项不存在");
    		continue;
    	}
    	if(a==6) System.exit(0);
    	switch(a) {
    	case 1:sushechaxun();break;
    	case 2:anpaixinsushe();break;
    	case 3:tiaozhengsushe();break;
    	case 4:susheweishengpingjia();break;
    	case 5:weishengjianchaqingkuang();break;
    	}
    	}
    	
	}
      
     public static void show() {
    	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 String zhuangtai(RoomInformation c){
    	  int count=0;
    	  StringBuilder s=new StringBuilder("");
    	  if(c.getStunno1().length()!=0) count++;
    	  if(c.getStunno2().length()!=0) count++;
    	  if(c.getStunno3().length()!=0) count++;
    	  if(c.getStunno4().length()!=0) count++;
    	  if(count==0) s.append("空宿舍");
    	  if(count==1) s.append("空3人");
    	  if(count==2) s.append("空2人");
    	  if(count==3) s.append("空1人");
    	  if(count==4) s.append("已满");
    	  return s.toString();
     }
     
     public static int renshu(RoomInformation c){
   	  int count=0;
   	  if(c.getStunno1().length()!=0) count++;
   	  if(c.getStunno2().length()!=0) count++;
   	  if(c.getStunno3().length()!=0) count++;
   	  if(c.getStunno4().length()!=0) count++;
   	  return count;
    }
     
	 public static void sushechaxun(){
		    System.out.println("***********************************************************");
	    	System.out.println("                      石家庄铁道大学                           ");
	    	System.out.println("                  学生公寓管理系统v2022                        ");
	    	System.out.println("***********************************************************");
	    	System.out.println("                     宿舍详细信息列表                          ");
	    for(int i=0;i<10;i++)
	        System.out.println("                    "+(i+1)+"、"+"  "+s[i].getRoomno()+"  "
	         +renshu(s[i])+"人  "+zhuangtai(s[i])+"                    ");
	        System.out.println("***********************************************************");
	}
     
	 public static int anpaixinsushe() {
		    int count=0; 
		    int k=0;
		    System.out.println("***********************************************************");
	    	System.out.println("                      石家庄铁道大学                           ");
	    	System.out.println("                  学生公寓管理系统v2022                        ");
	    	System.out.println("                       安排新宿舍                             ");
	    	System.out.println("***********************************************************");
	    	System.out.println("                    空宿舍详细信息列表                          ");
	    	for(int i=0;i<10;i++)
	    	   if(renshu(s[i])==0) {
	    		   count++;
	    		System.out.println("                    "+count+"、"+"  "+s[i].getRoomno()+"  "
	    				+renshu(s[i])+"人  "+zhuangtai(s[i])+"                    ");
	    	   }
	    	System.out.print("                    请输入新宿舍号:");
	    	String a=sc.next();
	    	int r=0;
	    	for(int i=0;i<10;i++)
	    	if(a.equals(s[i].getRoomno())) {
	    		if(renshu(s[i])==0)
	    			r=1;
	    		k=i;
	    		break;
	    	}
	    	if(r==0) {System.out.println("该宿舍不是空宿舍,无法安排新生");}
	    	if(r==1) {
	    		System.out.println("***********************************************************\r\n"
	    				         + "                     石家庄铁道大学\r\n"
	    				         + "                  学生公寓管理系统v2022\r\n"
	    				         + "                     安排新宿舍\r\n"
	    				         + "***********************************************************\r\n"
	    				         + "                      新宿舍号:");
	    		System.out.println("                      1、床位1:");
	    		System.out.println("                      2、床位2:");
	    		System.out.println("                      3、床位3:");
	    		System.out.println("                      4、床位4:");
	    		String a1=sc.next();
	    		while(panduan(a1)==0) {
	    			System.out.println("该学生已分配宿舍");
	    			System.out.println("请重新输入");
	    			a1=sc.next();
	    		}
	    		if(a1.equals("END")) return 1;
	    		else s[k].setStunno1(a1);
	    		String a2=sc.next();
	    		while(panduan(a2)==0) {
	    			System.out.println("该学生已分配宿舍");
	    			System.out.println("请重新输入");
	    			a2=sc.next();
	    		}
	    		if(a2.equals("END")) return 1;
	    		else s[k].setStunno1(a2);
	    		String a3=sc.next();
	    		while(panduan(a3)==0) {
	    			System.out.println("该学生已分配宿舍");
	    			System.out.println("请重新输入");
	    			a3=sc.next();
	    		}
	    		if(a3.equals("END")) return 1;
	    		else s[k].setStunno1(a3);
	    		String a4=sc.next();
	    		while(panduan(a4)==0) {
	    			System.out.println("该学生已分配宿舍");
	    			System.out.println("请重新输入");
	    			a4=sc.next();
	    		}
	    		if(a4.equals("END")) return 1;
	    		else  s[k].setStunno1(a4);System.out.println("该宿舍已满");
	    	}
	    	return 1;
	 }
	 
	 public static int panduan(String a) {
		 
		 for(int i=0;i<10;i++){
			 int count=0;
			 if(a.equals(s[i].getStunno1())) count++; 
			 if(a.equals(s[i].getStunno2())) count++; 
			 if(a.equals(s[i].getStunno3())) count++; 
			 if(a.equals(s[i].getStunno4())) count++; 
			 if(count!=0) return 0;
		 }
		 return 1;
	 }
	 
	 public static int tiaozhengsushe() {
		    int count=0;
		    int k=0;
		    System.out.println("***********************************************************");
	    	System.out.println("                      石家庄铁道大学                           ");
	    	System.out.println("                  学生公寓管理系统v2022                        ");
	    	System.out.println("                        调整宿舍                              ");
	    	System.out.println("***********************************************************");
	    	System.out.println("                    有空床位宿舍详细信息列表                      ");
	    	for(int i=0;i<10;i++)
	    		if(renshu(s[i])>0&&renshu(s[i])<4) {
		    		   count++;
		    		System.out.println("                    "+count+"、"+"  "+s[i].getRoomno()+"  "
		    				+renshu(s[i])+"人  "+zhuangtai(s[i])+"                    ");
		    	   }
	    	System.out.print("                    请输入待调整宿舍号:");
	    	String a=sc.next();
	    	int r=0;
	    	for(int i=0;i<10;i++)
	    	if(a.equals(s[i].getRoomno())) {
	    		if(renshu(s[i])>=1&&renshu(s[i])<=3)
	    			r=1;
	    		k=i;
	    		break;
	    	}
	    	if(r==0) {System.out.println("该宿舍没有空床位,无法调整");}
	    	if(r==1) {
	    		int i=0;
	    		System.out.println("***********************************************************\r\n"
	    				         + "                     石家庄铁道大学\r\n"
	    				         + "                  学生公寓管理系统v2022\r\n"
	    				         + "                       调整宿舍\r\n"
	    				         + "***********************************************************\r\n"
	    			             + "                      待调整宿舍号:");
	    		if(s[k].getStunno1().length()!=0)  
	    			i++;
	    		System.out.println("                     1、床位1: "+s[k].getStunno1());
	    		if(s[k].getStunno2().length()!=0) 
	    			i++;
	    		System.out.println("                     2、床位2: "+s[k].getStunno2());
	    		if(s[k].getStunno3().length()!=0) 
	    			i++;
	    		System.out.println("                     3、床位3: "+s[k].getStunno3());
	    		if(s[k].getStunno4().length()!=0) 
	    			i++;
	    		System.out.println("                     4、床位4: "+s[k].getStunno4());
	    		String a1=sc.next();
	    		while(panduan(a1)==0) {
	    			System.out.println("该学生已分配宿舍");
	    			System.out.println("请重新输入");
	    			a1=sc.next();
	    		}
	    		if(a1.equals("END")) return 1;
	    		else {if(s[k].getStunno1().length()==0) s[k].setStunno1(a1);
	    		      else  if(s[k].getStunno2().length()==0) s[k].setStunno2(a1);
	    		      else  if(s[k].getStunno3().length()==0) s[k].setStunno3(a1);
	    		      else  s[k].setStunno4(a1);
	    		      }
	    		i++;
	    		if(i!=4) {
	    		String a2=sc.next();
	    		while(panduan(a2)==0) {
	    			System.out.println("该学生已分配宿舍");
	    			System.out.println("请重新输入");
	    			a2=sc.next();
	    		}
	    		if(a2.equals("END")) return 1;
	    		else {if(s[k].getStunno1().length()==0) s[k].setStunno1(a2);
  		              else  if(s[k].getStunno2().length()==0) s[k].setStunno2(a2);
  		              else  if(s[k].getStunno3().length()==0) s[k].setStunno3(a2);
  		             else  s[k].setStunno4(a2);
  		             }
	    		}
	    		else {System.out.println("该宿舍已满"); return 1;}
	    		i++;
	    		if(i!=4) {
	    		String a3=sc.next();
	    		while(panduan(a3)==0) {
	    			System.out.println("该学生已分配宿舍");
	    			System.out.println("请重新输入:");
	    			a3=sc.next();
	    		}
	    		if(a3.equals("END")) return 1;
	    		else {if(s[k].getStunno1().length()==0) s[k].setStunno1(a3);
  		              else  if(s[k].getStunno2().length()==0) s[k].setStunno2(a3);
  		              else  if(s[k].getStunno3().length()==0) s[k].setStunno3(a3);
  		             else  s[k].setStunno4(a3);
  		             }
	    		}
	    		else {System.out.println("该宿舍已满"); return 1;}
	    		
	    	}
	    	return 1;
	 }
	 
	 public static void susheweishengpingjia() { 
		    int r=0;
		    int k=0;
		    while(r==0) {
		    System.out.println("***********************************************************");
	    	System.out.println("                      石家庄铁道大学                           ");
	    	System.out.println("                  学生公寓管理系统v2022                        ");
	    	System.out.println("                       宿舍卫生评价                           ");
	    	System.out.println("***********************************************************");
	    	System.out.println("                    请输入待评价宿舍号:");
	    	String a=sc.next();
	    	for(int i=0;i<10;i++)
	    	if(a.equals(s[i].getRoomno())) {
	    		if(renshu(s[i])!=0)
	    			r=1;
	    		k=i;
	    		break;
	    	}
	    	if(r==0) {System.out.println("该宿舍为空宿舍");}
	    	if(r==1) {
	    		System.out.println("                    1、"+"床位1  "
		         +s[k].getStunno1()+"                      ");
	    		System.out.println("                    2、"+"床位2  "
	   		         +s[k].getStunno1()+"                      ");
	    		System.out.println("                    3、"+"床位3  "
	   		         +s[k].getStunno1()+"                      ");
	    		System.out.println("                    4、"+"床位4  "
	   		         +s[k].getStunno1()+"                      ");
	    		System.out.println("输入宿舍卫生评价分数:");
	    		int w=sc.nextInt();
	    		while(w>100||w<0){
	    			System.out.println("输入错误");
	    			System.out.println("请重新输入:");
	    			w=sc.nextInt();
	    			}
	    		s[k].setHygienescore(w);
	    	}
		    } 
	 }
	 
	  public static String weishengdengji(RoomInformation c){
	  StringBuilder s=new StringBuilder("");
   	  if(c.getHygienescore()>=90) s.append("优秀");
   	  else if(c.getHygienescore()>=80) s.append("良好");
   	  else if(c.getHygienescore()>=60) s.append("合格");
      else  s.append("不合格");
   	  return s.toString();
      }
	 
	 public static void weishengjianchaqingkuang() {
		    System.out.println("***********************************************************");
	    	System.out.println("                      石家庄铁道大学                           ");
	    	System.out.println("                  学生公寓管理系统v2022                        ");
	    	System.out.println("                      卫生检查情况查询                           ");
	    	System.out.println("***********************************************************");
	    	System.out.println("                     宿舍卫生检查情况信息                        ");
	    	for(int i=0;i<10;i++)
		        System.out.println("                    "+(i+1)+"、"+"  "+s[i].getRoomno()+"  "
		         +s[i].getHygienescore()+"   "+weishengdengji(s[i]));
		        System.out.println("***********************************************************");
	 }
	 
}

  

标签:RoomInformation,Java,String,void,感想,System,new,开学,public
来源: https://www.cnblogs.com/yitongtianxia666/p/16690808.html