JAVA基础第七天

学生管理系统:

import javax.swing.JOptionPane;

public class XsGlXt {
public static String[] xm =new String[20];
public static int[] xh =new int[20];
public static int[] cj=new int[20];
public static int num=0;

   public static void main(String[] aaa){
  JOptionPane.showMessageDialog(null, "欢迎光临");
  boolean land = denglu();{
if(land==false){
JOptionPane.showMessageDialog(null, "非法用户");
System.exit(0);
}
  }
  while(true){
String s =JOptionPane.showInputDialog(null,"1、添加"+"\n"+"2、显示"+"\n"+"3、删除"+"\n"+"4、查找"+"\n"+"5、修改"+"\n"+"6、排序"+"\n"+"7、退出");
int item =Integer.parseInt(s);
switch (item) {
case 1:
add();
break;
case 2:
show();
break;
case 3:
del();
break;
case 4:
find();
break;
case 5:
amend();
break;
case 6:
sort();
break;


case 7:
JOptionPane.showMessageDialog(null, "谢谢使用");
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null, "非法输入,请输入1-7");
break;
}
}
            
}
   //修改学号,姓名,成绩
   public static void amend() {
// TODO 自动生成方法存根
 
  String z = JOptionPane.showInputDialog(null,"请输入需要修改的名字");
  for(int i=0;i<num;i++){
  if(z.equals(xm[i])){
String a=  JOptionPane.showInputDialog(null,"请输入学号");
String b=  JOptionPane.showInputDialog(null,"请输入姓名");
String c=  JOptionPane.showInputDialog(null,"请输入成绩");
xm[i]=b;
xh[i]=Integer.parseInt(a);
cj[i]=Integer.parseInt(c);
  }
  else{
  JOptionPane.showMessageDialog(null, "查无此人");
  }
  
  }
  
}
//排序
   private static void sort() {
// TODO 自动生成方法存根
  for (int i = 0; i < num; i++) {
for (int j = 0; j < num-1; j++) {
if (cj[i]>cj[j]) {
int a,c;
String b="";
a=cj[i];
cj[i]=cj[j];
cj[j]=a;
b=xm[i];
xm[i]=xm[j];
xm[j]=b;
c=xh[i];
xh[i]=xh[j];
xh[j]=c;
}
}
}
               show();
}

   //删除姓名,学号,成绩
public static void del() {

String s=JOptionPane.showInputDialog(null,"请输入要删除的名字");
for(int i=0;i<num;i++){
if(s.equals(xm[i])){
xm[i]=xm[i+1];
xh[i]=xh[i+1];
cj[i]=cj[i+1];
num--;
show();
}
else{
JOptionPane.showMessageDialog(null, "查无此人");
}

}


}
//查找
  public static void find() {
// TODO 自动生成方法存根
  String c=JOptionPane.showInputDialog("请输入姓名");

for (int i = 0; i < num; i++) {
if (xm[i].equals(c)) {

JOptionPane.showMessageDialog(null, "学号"+xh[i]+"  "+"姓名"+xm[i]+"   "+"成绩"+cj[i]);

}
else{
JOptionPane.showMessageDialog(null, "查无此人");
}
}

                 }
  //输入登陆

public static boolean denglu(){
  for(int i=0;i<3;i++){
String card =JOptionPane.showInputDialog(null,"请输入用户名");
String psw = JOptionPane.showInputDialog(null,"请输入密码");
if(card.equals("123456")&& psw.equals("aaaaaa")){
return true;
}
else{
JOptionPane.showMessageDialog(null, "用户名或密码错误");

}
}
return false;

}  
//添加学号,姓名,成绩
  public static void add(){
     
String s= JOptionPane.showInputDialog(null,"请输入学号");
 
String x= JOptionPane.showInputDialog(null,"请输入姓名");
String y= JOptionPane.showInputDialog(null,"请输入成绩");
xh[num] = Integer.parseInt(s); 
xm[num] = x;
cj[num] = Integer.parseInt(y);
   num++;
   String t = JOptionPane.showInputDialog(null,"是否显示在校学生?y/n");
   if(t.equalsIgnoreCase("y")){
    show();
   }
  
  } 
  //显示
     public static void show(){
     String str ="学号    姓名     成绩\n";
     
    for(int i=0;i<num;i++){
     str = str+xh[i]+"   "+xm[i]+"   "+cj[i]+"\n";
     
    }
    JOptionPane.showMessageDialog(null, str);
  
  } 
  
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值