作了一個小型的成績管理系統。主要代碼以下:java
/*
* 功能:簡易學生成績管理系統
*/
package day7;it
import java.util.Scanner;class
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) {import
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++) {im
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();
}
}next