import javax.swing.JOptionPane;
import java.util.Arrays;
class StudentManage
{
static String[]name = new String[20];
static int[]sn = new int[20];
static int[]score = new int[20];
static int num = 0;
public static void main(String[] args)
{
JOptionPane.showMessageDialog(null,"欢迎光临!");
boolean b = land();
if (b == false)
{
JOptionPane.showMessageDialog(null,"非法用户!");
System.exit(0);
}
while(true)
{
String Item = JOptionPane.showInputDialog(null,"1:添加\n2:显示\n3:删除\n4:查找\n5:修改\n6:排序\n7:退出");
int item = Integer.parseInt(Item);
switch(item)
{
case 1:
{
add();break;
}
case 2:
{
display();break;
}
case 3:
{
del();break;
}
case 4:
{
find();break;
}
case 5:
{
change();break;
}
case 6:
{
sort();break;
}
case 7:
{
JOptionPane.showMessageDialog(null,"谢谢使用!");
System.exit(0);
}
default:
{
JOptionPane.showMessageDialog(null,"输入错误,请输入数字1—7");
}
}
}
}
//
public static boolean land()
{
for(int n = 0;n < 3; n++)
{
String psd = JOptionPane.showInputDialog(null,"请输入用户名:");
String code = JOptionPane.showInputDialog(null,"请输入密码:");
if(psd.equals("chenxijun")&&code.equals("860227"))
{
return true;
}
else if(n<2)
{
JOptionPane.showMessageDialog(null,"用户名或密码错误,请重新输入");
}
}
return false;
}
public static void add()
{
for(int n = num; n < 20; n++)
{
String Sn = JOptionPane.showInputDialog(null,"请输入学号");
int sn1 = Integer.parseInt(Sn);
for(int m = 0; m < num; m++)
{
if(sn1==sn[m])
{
JOptionPane.showMessageDialog(null,"该学号已存在!");
return;
}
}
sn[n]= sn1;
name[n] = JOptionPane.showInputDialog(null,"请输入姓名");
String Score = JOptionPane.showInputDialog(null,"请输入成绩");
score[n] = Integer.parseInt(Score);
num++;
String s = JOptionPane.showInputDialog(null,"是否查看数据并返回选项菜单?y/n");
if(s.equals("y"))
{
display();
return;
}
}
}
public static void del()
{
String Name = JOptionPane.showInputDialog(null,"请输入要删除的学生姓名:");
for(int i = 0; i < num; i++)
{
if(Name.equals(name[i]))
{
if(i < num)
{
for(int j = i+1; j < num ;j++)
{
name[i] = name[j];
sn[i] = sn[j];
score[i] = score[j];
}
}
num --;
display();
return;
}
}
JOptionPane.showMessageDialog(null,"查无此人!");
display();
}
public static void display()
{
String str = "姓名 学号 成绩";
for(int n = 0; n < num; n++)
{
str += "\n"+name[n]+" "+sn[n]+" "+score[n]+"\n";
}
JOptionPane.showMessageDialog(null,str);
}
public static void find()
{
String str = "姓名 学号 成绩";
String Name = JOptionPane.showInputDialog(null,"请输入要查找的学生姓名:");
for(int n = 0; n < num; n++)
{
if(Name.equals(name[n]))
{
JOptionPane.showMessageDialog(null,str+"\n"+name[n]+" "+sn[n]+" "+score[n]);
return;
}
}
JOptionPane.showMessageDialog(null,"查无此人!");
}
public static void sort()
{
display();
for(int i = 0; i < num; i++)
{
for(int j = i+1; j < num; j++)
{
if(score[i] < score[j])
{
int t1 = score[i];
score[i] = score[j];
score[j] = t1;
int t2 = sn[i];
sn[i] = sn[j];
sn[j] = t2;
String t3 = name[i];
name[i] = name[j];
name[j] = t3;
}
}
}
display();
}
public static void change()
{
String Name = JOptionPane.showInputDialog(null,"请输入要修改的学生姓名:");
for(int i = 0; i < num; i++)
{
if(Name.equals(name[i]))
{
String Name1 = JOptionPane.showInputDialog(null,"请输入姓名:");
String SN = JOptionPane.showInputDialog(null,"请输入学号:");
String SCore = JOptionPane.showInputDialog(null,"请输入成绩:");
sn[i] = Integer.parseInt(SN);
score[i] = Integer.parseInt(SCore);
name[i] = Name1;
display();
return;
}
}
}
}
import java.util.Arrays;
class StudentManage
{
static String[]name = new String[20];
static int[]sn = new int[20];
static int[]score = new int[20];
static int num = 0;
public static void main(String[] args)
{
JOptionPane.showMessageDialog(null,"欢迎光临!");
boolean b = land();
if (b == false)
{
JOptionPane.showMessageDialog(null,"非法用户!");
System.exit(0);
}
while(true)
{
String Item = JOptionPane.showInputDialog(null,"1:添加\n2:显示\n3:删除\n4:查找\n5:修改\n6:排序\n7:退出");
int item = Integer.parseInt(Item);
switch(item)
{
case 1:
{
add();break;
}
case 2:
{
display();break;
}
case 3:
{
del();break;
}
case 4:
{
find();break;
}
case 5:
{
change();break;
}
case 6:
{
sort();break;
}
case 7:
{
JOptionPane.showMessageDialog(null,"谢谢使用!");
System.exit(0);
}
default:
{
JOptionPane.showMessageDialog(null,"输入错误,请输入数字1—7");
}
}
}
}
//
public static boolean land()
{
for(int n = 0;n < 3; n++)
{
String psd = JOptionPane.showInputDialog(null,"请输入用户名:");
String code = JOptionPane.showInputDialog(null,"请输入密码:");
if(psd.equals("chenxijun")&&code.equals("860227"))
{
return true;
}
else if(n<2)
{
JOptionPane.showMessageDialog(null,"用户名或密码错误,请重新输入");
}
}
return false;
}
public static void add()
{
for(int n = num; n < 20; n++)
{
String Sn = JOptionPane.showInputDialog(null,"请输入学号");
int sn1 = Integer.parseInt(Sn);
for(int m = 0; m < num; m++)
{
if(sn1==sn[m])
{
JOptionPane.showMessageDialog(null,"该学号已存在!");
return;
}
}
sn[n]= sn1;
name[n] = JOptionPane.showInputDialog(null,"请输入姓名");
String Score = JOptionPane.showInputDialog(null,"请输入成绩");
score[n] = Integer.parseInt(Score);
num++;
String s = JOptionPane.showInputDialog(null,"是否查看数据并返回选项菜单?y/n");
if(s.equals("y"))
{
display();
return;
}
}
}
public static void del()
{
String Name = JOptionPane.showInputDialog(null,"请输入要删除的学生姓名:");
for(int i = 0; i < num; i++)
{
if(Name.equals(name[i]))
{
if(i < num)
{
for(int j = i+1; j < num ;j++)
{
name[i] = name[j];
sn[i] = sn[j];
score[i] = score[j];
}
}
num --;
display();
return;
}
}
JOptionPane.showMessageDialog(null,"查无此人!");
display();
}
public static void display()
{
String str = "姓名 学号 成绩";
for(int n = 0; n < num; n++)
{
str += "\n"+name[n]+" "+sn[n]+" "+score[n]+"\n";
}
JOptionPane.showMessageDialog(null,str);
}
public static void find()
{
String str = "姓名 学号 成绩";
String Name = JOptionPane.showInputDialog(null,"请输入要查找的学生姓名:");
for(int n = 0; n < num; n++)
{
if(Name.equals(name[n]))
{
JOptionPane.showMessageDialog(null,str+"\n"+name[n]+" "+sn[n]+" "+score[n]);
return;
}
}
JOptionPane.showMessageDialog(null,"查无此人!");
}
public static void sort()
{
display();
for(int i = 0; i < num; i++)
{
for(int j = i+1; j < num; j++)
{
if(score[i] < score[j])
{
int t1 = score[i];
score[i] = score[j];
score[j] = t1;
int t2 = sn[i];
sn[i] = sn[j];
sn[j] = t2;
String t3 = name[i];
name[i] = name[j];
name[j] = t3;
}
}
}
display();
}
public static void change()
{
String Name = JOptionPane.showInputDialog(null,"请输入要修改的学生姓名:");
for(int i = 0; i < num; i++)
{
if(Name.equals(name[i]))
{
String Name1 = JOptionPane.showInputDialog(null,"请输入姓名:");
String SN = JOptionPane.showInputDialog(null,"请输入学号:");
String SCore = JOptionPane.showInputDialog(null,"请输入成绩:");
sn[i] = Integer.parseInt(SN);
score[i] = Integer.parseInt(SCore);
name[i] = Name1;
display();
return;
}
}
}
}