day7 方法及基础知识运用

做了一个小型的成绩管理系统。主要代码如下:

/*
 * 功能:简易学生成绩管理系统
 */
package day7;

import java.util.Scanner;

public class HomeWork {
 static Scanner scan=new Scanner(System.in);
 static String[] user=new String[2];
 static String[] password=new String[2];
 static String[] name=new String[5];
 static int[] score=new int[name.length];
 static boolean c=false;
 public static void main(String[] args) {

  fun();
 }
 public static void fun(){
  while(true){
  System.out.println("欢迎使用简易成绩管理系统0.0");
  System.out.println("A注册");
  System.out.println("B登录");
  System.out.println("C退出");

  char str=scan.next().charAt(0);
  switch(str){
  case 'A':
   register(user,password);
   break;
  case 'B':
   login(user,password);
   break;
  case 'C':
   System.out.println("退出成功!!!");
   System.exit(0);
   break;
  default :
   System.out.println("输入有误,请重新输入。");
  }
  }
 
 }
 public static void register(String user[],String password[]){
  for (int i = 0; i < user.length; i++) {
   if(user[i]==null){System.out.println("请输入用户名:");
   user[i]=scan.next();
   System.out.println("请输入密码:");
   password[i]=scan.next();
   System.out.println("注册成功,返回登录!!!");
   fun();
   }

   }
  System.out.println("用户已经达到上限,请联系管理员。");
  
  }
 
 public static void login(String user[],String password[]){
  System.out.println("请输入用户名");
  String str1=scan.next();
  System.out.println("请输入密码:");
  String str2=scan.next();
  for (int i = 0; i < user.length; i++) {
   if(str1.equals(user[i])&&str2.equals(password[i])){
    System.out.println("登录成功!!!欢迎您!!!");
    fun1();
   }else{
    System.out.println("没找到该用户!请重新登录");
    fun();
   }
  }
  
 }
 public static void fun1(){
  System.out.println("A增加学生分数信息");
  System.out.println("B修改学生分数信息");
  System.out.println("C删除学生分数信息");
  System.out.println("D查询学生信息");
  System.out.println("E返回上级菜单");
  char str=scan.next().charAt(0);
  switch(str){
  case 'A':
   add(name,score);
   break;
  case 'B':
   modify(name,score);
   break;
  case 'C':
   delete(name,score);
   break;
  case 'D':
   insert(name,score);
   break;
  case 'E':
   fun();
   break;
  }
  
 }
 public static void add(String[] name,int[] score){
  for (int i = 0; i < name.length; i++) {
   System.out.println("请输入第"+(i+1)+"个学生的名字:");
   name[i]=scan.next();
   System.out.println("请输入第"+(i+1)+"个学生的分数:");
   score[i]=scan.nextInt();
  }
  System.out.println("新增学生信息成功!!!返回上级菜单");
  fun1();
 }
 public static void delete(String[] name,int[] score){
  System.out.println("请输入你要删除的学生姓名:");
  String str=scan.next();   
  if(name[0].equals(str)){
   System.out.println("成功删除了"+name[0]+"的信息");
   for (int j = 0; j < name.length; j++) {
    name[j]=name[j+1];
    score[j]=score[j+1];
    c=true;
    }
   }
  if(name[name.length-1].equals(str)){
   System.out.println("成功删除了"+name[name.length-1]+"的信息");
   name[name.length-1]=null;
   score[score.length-1]=0;
   c=true;
  }
  for (int i = 1; i < name.length; i++) {

   if(name[i-1].equals(str)){
    System.out.println("成功删除了"+name[i-1]+"的信息");
    name[i-1]=name[i];
    score[i-1]=score[i];
    c=true;
   }    
   }
  if(c){
   name[name.length-1]=null;
   score[score.length-1]=0;
   fun1();
  }else{
  System.out.println("没有找到该学的信息");
  fun1();
  }
  }
 public static void modify(String[] name,int[] score){
  System.out.println("请输入你要修改的学生姓名:");
  String str=scan.next();
  for (int i = 0; i < name.length; i++) {
   if(name[i].equals(str)){
    System.out.println("你要修改的是"+name[i]+"的分数,请输入你要修改的分数:");
    score[i]=scan.nextInt();
    System.out.println("修改成功!!!返回上级菜单");
    fun1();
   }else{
    System.out.println("没有找到该学的信息");
   }
  }
  
 }
 public static void insert(String[] name1,int[] score1){
  System.out.println("A查询一个学生分数:");
  System.out.println("B查询所有学生分数:");
  char str=scan.next().charAt(0);
  switch(str){
  case 'A':
   System.out.println("请输入查询的学生姓名:");
   String str1=scan.next();
   for (int i = 0; i < name1.length; i++) {
    if(name[i].equals(str1)){
     System.out.println("你查询的是"+name1[i]+"的分数,他的分数是:"+score1[i]);
     fun1();
    }
   }
   System.out.println("没有找到该学生的信息!!!");
   break;
  case 'B':
   for (int i = 0; i < name1.length; i++) {
    System.out.println(name1[i]+"的分数是:"+score1[i]);
   }
   break;
  }
  fun1();
 }
}

posted @ 2016-11-22 19:58  风少凌云  阅读(118)  评论(0编辑  收藏  举报