import java.util.Scanner;
class StudentManager {
static String[] name = new String[5];
static int[] code = new int[5];
static double[] score = new double[5];
public static void main(String[] args)
{
systemMain();
}
public static void systemMain(){
while(true){
System.out.println("************学生信息管理小系统**********");
core();
System.out.println("****************************************");
}
}
public static void core(){
System.out.println("1,添加学生信息");
System.out.println("2,修改学生信息");
System.out.println("3,删除学生信息");
System.out.println("4,查询学生信息");
System.out.println("5,退出系统");
System.out.println("请选择功能序号:");
//接收用户输入的功能序号(键盘录入)
int code = returnInt();
choose(code);
}
public static void choose(int code){
switch(code){
case 1:
//c[0] = returnInt();
//name[0] = returnString();
//score[0] = returnDouble();
add();
//systemMain();
break;
case 2:
change();
break;
case 3:
delete();
break;
case 4:
read();
//systemMain();
break;
default:
System.exit(1);
break;
}
}
public static void add(){
//String[] n = new String[5];
//[] c = new int[5];
//double[] s = new double[5];
//System.out.print("请添加学生信息:");
for(int i = 1;i<code.length+1;i++){
if(code[i]==0 && i>0){
System.out.println("************录入学生信息**********");
System.out.print("请录入学生学号:");
int c=returnInt();
code[i] = c;
System.out.print("请录入学生姓名:");
String n=returnString();
name[i] = n;
System.out.print("请录入学生成绩:");
double s=returnDouble();
score[i] = s;
System.out.println("学生信息添加完成!");
//System.out.println("****************************************");
break;
}else{
continue;
}
}
/*System.out.println("************录入学生信息**********");
System.out.print("请输入学生学号:");
int c1=returnInt();
System.out.print("请输入学生姓名:");
String n1=returnString();
System.out.print("请输入学生成绩:");
Double s1=returnDouble();
code[0]=c1;
name[0]=n1;
score[0]=s1;
System.out.print("学生信息添加完成!");
int c2=returnInt();
String n2=returnString();
Double s2=returnDouble();
code[1]=c2;
name[1]=n2;
score[1]=s2;
int c3=returnInt();
String n3=returnString();
Double s3=returnDouble();
code[2]=c3;
name[2]=n3;
score[2]=s3;
int c4=returnInt();
String n4=returnString();
Double s4=returnDouble();
code[3]=c4;
name[3]=n4;
score[3]=s4;
int c5=returnInt();
String n5=returnString();
Double s5=returnDouble();
code[4]=c5;
name[4]=n5;
score[4]=s5;*/
/*for(int i =0;i<code.length;i++){
code[i] = c;
}
for(int i=0 ;i<name.length;i++){
name[i] = n;
}
for(int i =0;i<code.length;i++){
score[i] = s;
}
//c[0] = code;
//n[0] = name;
//s[0] = score;*/
}
public static void change(){
System.out.println("************修改学生信息**********");
System.out.print("请输入需要修改的学生学号:");
int c= returnInt();
for(int i=0;i<code.length;i++){
if(c == code[i]){
System.out.println("学号"+"\t"+"姓名"+"\t"+"成绩");
System.out.println(code[i]+"\t"+name[i]+"\t"+score[i]);
System.out.print("请输入需要修改的成绩:");
double s =returnDouble();
double temp =0;
temp = score[i];
score[i] = s;
System.out.println("成绩修改完成,修改后的成绩如下:");
System.out.println(code[i]+"\t"+name[i]+"\t"+score[i]);
}
}
}
public static void delete(){
System.out.println("************删除学生信息**********");
System.out.print("请输入需要删除的学生学号:");
int c= returnInt();
for(int i=0;i<code.length;i++){
if(c == code[i]){
System.out.println("学号"+"\t"+"姓名"+"\t"+"成绩");
System.out.println(code[i]+"\t"+name[i]+"\t"+score[i]);
System.out.println("请确认是否需要删除,确认请输入1,否请输入0");
int c1= returnInt();
switch(c1){
case 1:
code[i]=0;
name[i]=null;
score[i]=0.0;
break;
case 0:
break;
default :
System.out.println("请输入1或者0");
}
}
}
}
public static void read(){
System.out.println("************查询学生信息**********");
System.out.println("1,查询全部学生信息");
System.out.println("2,根据姓名查询学生信息");
System.out.println("3,根据成绩显示学生信息");
System.out.print("请选择查询功能:");
//接收用户输入的功能序号(键盘录入)
int c = returnInt();
switch(c){
case 1:
System.out.println("学号"+"\t"+"姓名"+"\t"+"成绩");
for(int i =0;i<code.length || i<name.length || i<score.length;i++){
if(code[i] !=0){
System.out.println(code[i]+"\t"+name[i]+"\t"+score[i]);
}
}
break;
case 2:
System.out.print("请输入学生学号:");
int n = returnInt();
for(int i=1;i<code.length;i++){
//System.out.print(code[i-1] != n);
//System.out.print(code[i] != n);
//System.out.print(code[i+1] != n);
//System.out.print(code[i+2] != n);
if(code[i] != n){
//System.out.println("没有找到这个学生信息");
//continue;
//System.out.println(name[i]);
//System.out.println(n);
}else{
System.out.println("学号"+"\t"+"姓名"+"\t"+"成绩");
System.out.println(code[i]+"\t"+name[i]+"\t"+score[i]);
break;
}
}
break;
case 3:
break;
}
}
//接收字符串类型的数据
public static String returnString(){
Scanner input=new Scanner(System.in);
return input.next();
}
//接收int类型的数据
public static int returnInt(){
Scanner input=new Scanner(System.in);
return input.nextInt();
}
//接收double类型的数据
public static double returnDouble(){
Scanner input=new Scanner(System.in);
return input.nextDouble();
}
}
|
|