packagesubject jesse;
import java.io.*;public class stu
{ public static int bianhao=0,f_bh;
  public static int bh;
  public static String s;
public static class student
{   
public int bianhao;
public String name;
  public String subject;
  public String sex;
};
public static student[] st=new student[100];
   
public static void main(String args[])
{   
for(int i=0;i<=99;i++)
{ st[i]=new student();
st[i].bianhao=-1;
}
System.out.print("*******************\n**欢迎使用学生信息管理系统**\n*******************\n");
first();
  xz();  
 }
public static void xz()
{
while(true)
{
System.out.print("请输入:");
try
{ BufferedReader Console=new BufferedReader(new InputStreamReader(System.in));s=Console.readLine();
bh=Integer.parseInt(s);
break;
}
catch(Exception e)
{
System.out.print("你输入的有误,请输入(1,2,3,4,5,0)其中人一个\n");
}
}switch(bh)
{
case 0:break;
case 1:add();first();xz();break;
case 2:del();first();xz();break;
case 3:mod();first();xz();break;
case 4:find();first();xz();break;
case 5:showall();first();xz();break;}}
  public static void first()
{
    
System.out.print("1---增加\n");
System.out.print("2---删除\n");
System.out.print("3---修改\n");
System.out.print("4---查询\n");
System.out.print("5---显示\n");
System.out.print("0---退出\n");}
public static void add(){
while(true){
try{
BufferedReader Console=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入编号:"+(int)(bianhao+1));
st[bianhao].bianhao=(int)(bianhao+1);
System.out.print("请输入姓名:");
s=Console.readLine();
st[bianhao].name=s;
System.out.print("请输入科目:");
st[bianhao].subject=Integer.parseInt(Console.readLine());
System.out.print("请输入性别:");
s=Console.readLine();
st[bianhao].sex=s;
bianhao++;
  System.out.print("是否继续输入?(y/n)");
while(true)
{
s=Console.readLine();
if(!s.equals("y") && !s.equals("n"))
{
System.out.print("有错,请重新输入");}
else
{break;
}
}
if(s.equals("n"))
{
break;
}
}
  catch(Exception e)
  {
  System.out.print("错误");  }
}
}
public static void del()
{ try{
BufferedReader Console=new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入学生编号");
while(true)
{
f_bh=Integer.parseInt(Console.readLine());
if (f_bh>=1 && f_bh<=100)
{
if(show(f_bh-1))
{
System.out.print("确认删除?(y/n)");
while(true)
{
s=Console.readLine();
if(!s.equals("y") && !s.equals("n"))
{
System.out.print("有错,请重新输入");
}
else
{
break;
}
}
if(s.equals("n"))
{break;  
}
else if(s.equals("y"))
{
st[f_bh-1].bianhao=-1;
st[f_bh-1].name="";
st[f_bh-1].subject=0;
st[f_bh-1].sex="";
System.out.print("删除成功");
break;
}
}
else{break;
}}
else
{
System.out.print("你输入的编号不在1-100内,重输");
}
}}
catch(Exception e)
{System.out.print("错误");
  }
}
public static void mod()
  { try{
System.out.print("请输入学生编号");
while(true)
{BufferedReader Console=new BufferedReader(new InputStreamReader(System.in));
f_bh=Integer.parseInt(Console.readLine());
if (f_bh>=1 && f_bh<=100)
{
if(show(f_bh-1))
{
System.out.print("确认修改?(y/n)");
while(true)
{
s=Console.readLine();
if(!s.equals("y") && !s.equals("n"))
{
System.out.print("有错,请重新输入");
}if(s.equals("n"))
{  break;
}
else if(s.equals("y"))
{   
System.out.println("姓名当前值:"+st[f_bh-1].name+",更改为:(#表示不修改)");
    
s=Console.readLine();
if(!s.equals("#"))
st[f_bh-1].name=s;
System.out.println("科目当前值:"+st[f_bh-1].subject+",更改为:(#表示不修改)");
s=Console.readLine();
if(!s.equals("#"))
st[f_bh-1].subject=Integer.parseInt(s);
System.out.println("性别当前值:"+st[f_bh-1].sex+",更改为:(#表示不修改)");
s=Console.readLine();
if(!s.equals("#"))
st[f_bh-1].sex=s;
System.out.print("修改成功\n");  break;
}
}
}
break;
}
else
{
System.out.print("你输入的编号不在1-100内,重输");
}
}
}
catch(Exception e)
{
System.out.print("错误");
}
}
public static void find(){ try{
System.out.print("请输入学生编号");
while(true)
{ BufferedReader Console=new BufferedReader(new InputStreamReader(System.in));
f_bh=Integer.parseInt(Console.readLine());
if (f_bh>=1 && f_bh<=100)
{show(f_bh-1);
break;
}
else
{System.out.print("你输入的编号不在1-100内,重输");
}
}
}
catch(Exception e)
{System.out.print("错误");
}
}
public static void showall()
{ System.out.print("编号 姓名 年龄 性别\n");
for(int i=0;i<=99;i++)
if (st[i].bianhao!=-1)
{System.out.println(st[i].bianhao+" "+st[i].name+" "+st[i].subject+" "+st[i].sex+"\n");
}}
public static boolean show(int a)
{
if(st[a].bianhao!=-1)
{
System.out.println("编号 姓名 年龄 性别\n");
System.out.println(st[a].bianhao+" "+st[a].name+" "+st[a].subject+" "+st[a].sex+"\n");
  return true;
}
else
{System.out.print("无此记录或已被删除\n");
return false;
}
}}