2020-04-22

用数组写学生管理系统
因为用第一次用,代码排版不美观,eclipse使用Ctrl+shift+f快捷键,整理排版

package com05;
import java.util.Arrays;import java.util.Scanner;public class StudentManageTest 
{	static String[] no = {};	
    static String[] name = {};	
    static double[] score = {};
    	public static void main(String[] args) {		
    	System.out.println("************" + 
    	"欢迎来到学生管理系统"	
    	+"********************");		
    	do {System.out					
    	.println("--------------------------------------------------");			
    	System.out.println("请选择功能:1--成绩录入,2--成绩查询,3,成绩修改,4--查询列表,5--退出"	+ "\t");			
    	System.out.println("--------------------------------------------------");			
    	Scanner scan = new Scanner(System.in);			
    	int num = scan.nextInt();			
    	switch (num) {			
    	case (1):				
    	  input(scan);				
    	  break;			
    	case (2):				
    	  find(scan);				
    	  break;			
    	case (3):				
    	  update(scan);				
    	  break;			
    	case (4):				
    	  list();				
    	  break;			
    	case (5):				
    	  System.out.println("退出系统!!!");				
    	  System.exit(0);				
    	  break;			
    	default:				
    	System.out.println("输入错误!!!!!");	
    	   }		
    	} while (true);	}	


// 判断学号是否重复	
    	public static int isExist(String newNo) {		
    	int index = -1;		
    	for(int i = 0;i < no.length;i ++){
		   if(no[i].equals(newNo)){				
		   index = i;				
		   break;			
		   }		
		}		
		return index;	
}	
//录入成绩
public static void input(Scanner scan) {
		System.out.print("请输入学号:");
		String addNo = scan.next();		
		System.out.print("请输入姓名:");		
		String addName = scan.next();		
		System.out.print("请输入成绩:");		
		double addScore = scan.nextDouble();		
		if(isExist(addNo)==-1){			
		  no =Arrays.copyOf(no,no.length+1);			
		  no[no.length-1] = addNo;			
		  name = Arrays.copyOf(name, name.length+1);			
		  name[name.length-1] = addName;				  	 score=Arrays.copyOf(score,score.length+1);			
		  score[score.length-1] = addScore;			
		  System.out.println("录入成功!!!!!");		
		  }else{			
		  System.out.println("录入失败,该学生不存在!!!");		
		  }	
}	
//查找成绩
public static void find(Scanner scan){		
    System.out.print("请输入你要查找的学号:");		
    String newNo = scan.next();		
    int index = -1;		
    if((index = isExist(newNo)) != -1){			
    System.out.println("学号\t姓名\t成绩");			
 System.out.println(no[index]+"\t"+name[index]+"\t"+score[index]);		
     }else{			
        System.out.println("查找失败,该学生不存在");		
     }	
  }	
//修改成绩
public static void update(Scanner scan){		   
     System.out.print("请输入学号:");		
     String upNo = scan.next();		
     int index = -1;		
     if((index = isExist(upNo)) != -1){			
     System.out.print("请输入新的成绩:");			
     double upScore = scan.nextDouble();			
     score[index] = upScore;			
     System.out.println("修改成功");		
     }else{			
       System.out.println("修改失败,该学生不存在");		
      }	
 }	
//成绩列表
public static void list(){		    
   System.out.println("学号\t姓名\t成绩");		
   for(int i = 0;i < no.length;i ++){			
 System.out.println(no[i]+"\t"+name[i]+"\t"+
     score[i]);		
    }	
   }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值