java 用数组编写一个简单的学生管理系统

 
  
//StudentMain.java
public class StudentMain {
	public static void main(String[] args) {
			Scanner scn = new Scanner(System.in);  
	        System.out.print("请输入学生总人数");
	          int  count= scn.nextInt();
	          Student [] students=new Student [count];
	          while (true) {
	        	  System.out.println("1.新增一名学生 2.根据学号查询学生 3.根据学号修改学生 4. 根据学号删除一名学生 5. 查看所有学生  其他.退出");
	        	  int  x= scn.nextInt();
	        	  switch(x) {
	        	  case 1 : {
	        		  System.out.println("请输入学生编号");
	        		  String stuid=scn.next();
	        		  System.out.println("请输入学生姓名");
	        		  String name=scn.next();
	        		  System.out.println("请输入该学生语文成绩");
	        		   int  chinese= scn.nextInt();
	        		   System.out.println("请输入该学生数学成绩");
	        		   int  math= scn.nextInt();
	        		   System.out.println("请输入该学生英语成绩");
	        		   int  english= scn.nextInt();
	        		   Student student =new Student(stuid, name, chinese, math, english);
	        		   students=StudentAll.save(student, students);
	        		   break;
	        	  }
	        	  case 2:{
	        		  System.out.println("请输入学生编号");
	        		  String stuid=scn.next();
	        		  System.out.println(StudentAll.getStudent(stuid, students));
	        		  break;
	        	  }
	        	  case 3:{
	        		  System.out.println("请输入要修改的学生编号");
	        		  String stuid=scn.next();
	        		  System.out.println("请输入学生姓名");
	        		  String name=scn.next();
	        		  System.out.println("请输入该学生语文成绩");
	        		   int  chinese= scn.nextInt();
	        		   System.out.println("请输入该学生数学成绩");
	        		   int  math= scn.nextInt();
	        		   System.out.println("请输入该学生英语成绩");
	        		   int  english= scn.nextInt();
	        		   Student student =new Student(stuid, name, chinese, math, english);
	        		   students=StudentAll.update(stuid, student, students);
	        		   break;
	        	  }
	        	  case 4:{
	        		  System.out.println("请输入学生编号");
	        		  String stuid=scn.next();
	        		  students=StudentAll.delStudent(stuid, students);
	        		  break;
	        	  }
	        	  case 5:{
	        		  StudentAll.getStudeltAll(students);
	        		  break;
	        	  }default:{
	        		  System.exit(0);
	        	  }
	        	 
	        	  
	        	  }
	        	  
	          }
	          
	}
	
}
//Student.java

public class Student {
	private String stuid;
	private String name;
	private int chinese;
	private int math;
	private int english;
	private int avg;
	private int sum;
	public int getAvg() {
		return avg;
	}
	public void setAvg(int avg) {
		this.avg = avg;
	}
	public int getSum() {
		return sum;
	}
	public void setSum(int sum) {
		this.sum = sum;
	}
	public String getStuid() {
		return stuid;
	}
	public void setStuid(String stuid) {
		this.stuid = stuid;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getChinese() {
		return chinese;
	}
	public void setChinese(int chinese) {
		this.chinese = chinese;
	}
	public int getMath() {
		return math;
	}
	public void setMath(int math) {
		this.math = math;
	}
	public int getEnglish() {
		return english;
	}
	public void setEnglish(int english) {
		this.english = english;
	}
	
	public String getMessage() {
		String messages="学生编号 :"+this.stuid+" 学生姓名: "+this.name+" 语文:"+this.chinese+" 数学:"+this.math+" 英语: "+this.english+" 总分 :"+this.sum+" 平均分 :"+this.avg;
		return messages;
	}
	
	public Student(String stuid,String name,int chinese,int  math, int english) {
		this.chinese=chinese;
		this.english=english;
		this.math=math;
		this.name=name;
		this.stuid=stuid;
		this.sum=chinese+math+english;
		this.avg=this.sum/3;
	}
	public Student() {
		
	}
	
}
//StudentAll.java
public class StudentAll {
	
	
	 public   static  Student[]   save(Student student,Student [] students) {
		 
		boolean fal=checkSid(student.getStuid(), students);//先查询是否有这个 学生编号
		 if(fal) {
			System.out.println("该学生编号已存在,请重新输入");
			return students;
		 }
		 for(int i=0;i

 
 

你可能感兴趣的:(java 用数组编写一个简单的学生管理系统)