Java学生信息管理系统

package venus;

import java.util.Scanner;

public class Test 
{
	static int index = 0;
	static Student students[] = new Student[45];
	
	public static void main(String[] args) 
	{
	      System.out.println("***********************************");
	      System.out.println("*           欢迎使用学生管理系统                                *");
	      
	      for (;;)
	      {
	    	  menu();
	      }
	}
	      
    private static void menu()
    {
    	  System.out.println("***********************************");
	      System.out.println("*           1:添加学生信息                                          *");
		  System.out.println("*           2:删除学生信息                                          *");
		  System.out.println("*           3:修改学生信息                                          *");
		  System.out.println("*           4:查询学生信息                                          *");
		  System.out.println("***********************************");
		  System.out.print("请输入操作项:");
		  Scanner scanner = new Scanner(System.in);
	      int option = scanner.nextInt();
	      switch (option) 
		  {
		      case 1:{
		    	     if (index > students.length - 1)

		    	     {
		    		     System.out.println("学生数已达到上限");
		    	 	     break;
		    	     }		    	  
		    	  
		    	     Student student = new Student();
		             System.out.print("请输入学    号:");
		             String id = scanner.next();
		             student.setId(id);
		             
		             if(index != 0)
		             {
			             for (Student stu : students)
			             {
			            	 if (stu == null)
				             {
				    	         break;
				             }
			            	 if(stu.getId().equals(student.getId()))
			            	 {
			            		 System.out.println("学号重复,请重新输入");
			            		 return;
			            	 }	 
			             }		            	 
		             }
		             
		             System.out.print("请输入姓    名:");
		             String name = scanner.next();
		             student.setName(name);
		             System.out.print("请输入手机号:");
		             String mobile = scanner.next();
		             student.setMoblie(mobile);
		             System.out.print("请输入住    址:");
		             String address = scanner.next();
		             student.setAddress(address);	           
	                 
		             students[index] = student;
		             index += 1;
		             System.out.println("添加成功,按任意键继续");
		             break;
		      } 
		      case 2:{
		    	     System.out.print("输入学生学号:"); 
		    	     String id = scanner.next();
	                 boolean hasDate = false;
	                 int i = 0;
	                 
	                 for(;i < students.length; i ++)
	                 {
	                	 if (students[i] == null)
	                	 {
	                		 break;
	                	 }
	                	 if (id.equals(students[i].getId()))
	                	 {
	                		 hasDate = true;
	                		 break;
	                	 }
	                 }
	      
		             if(! hasDate)
	            	 {
	            		 System.out.println("未能找到学号为:" + id + "的学生信息");
	            		 return;
	            	 }
		             
		             for(; i < students.length; i ++)
		             {
		            	 if (i == students.length - 1)
		            	 {
		            		 students[i] = null;
		            		 break;
		            	 }
		            	 students[i] = students[i + 1];
		            	 if (students[i + 1] == null)
		            	 {
		            		 break;
		            	 }
		             }
		             
		             System.out.println("删除成功,按任意键继续");
		       
		             index --;
		             
		             return;
		      }
		      case 3:{
		    	     System.out.print("输入学生学号:"); 
		             String id = scanner.next();
		             boolean hasDate = false;
		             
		             for(Student student : students)
		             {
		            	 if (student == null)
		            	 {
		            		 break;
		            	 }
		            	 if (student.getId().equals(id));//id
		            	 {
				             System.out.print("请输入姓    名:");
				             String name = scanner.next();
				             student.setName(name);
				             System.out.print("请输入手机号:");
				             String mobile = scanner.next();
				             student.setMoblie(mobile);
				             System.out.print("请输入住    址:");
				             String address = scanner.next();
				             student.setAddress(address);
				             System.out.println("修改成功");
				             
				             hasDate = true;
				             return;
		            	 }
		             }
	            	 if(! hasDate)
	            	 {
	            		 System.out.println("不存在学号为:" + id + "的学生!!!");
	            	 }
	            	 return;
		      }
		      case 4:{
		    	     System.out.print("输入学生名字:");
		             String name = scanner.next();
		             boolean hasDate = false;
		             for(Student student : students)
		             {
		            	 if (student == null)
		            	 {
		            		 break;
		            	 }
		            	 if (student.getName().equals(name));
		            	 {
		            		 System.out.println(student);
		            		 hasDate = true;
		            	 }	 
		             }
		             if (!hasDate)
	            	 {
	            		 System.out.println("不存在名字为:" + name + "的学生!!!");
	            	 }
		             return;
		      }
	          default:System.out.println("系统无法找到" + option + "选项,请按任意键继续");
	     }     	  
    }
}
package venus;

public class Student 
{
	private String id;
	private String name;
	private String moblie;
	private String address;

	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getMoblie() {
		return moblie;
	}
	public void setMoblie(String moblie) {
		this.moblie = moblie;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	
	@Override
	public String toString() {
		return "该生的[学号 = " + id + ",名字 = " + name + ",手机号 = " + moblie + ",住址 = " + address + "]";
	}
	

}

你可能感兴趣的:(java)