第一个小项目

public class Student4{
public static String[] name = new String[20]; 
public static int[] XueHao = new int[20]; 
public static int[] ChengJi =  new int[20];   

public static int num = 0;   


public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "欢迎使用冷凌云客服端");
boolean island =DengLu();
if (island == false) {
JOptionPane.showMessageDialog(null, "非法用户");
System.exit(0);
}

while (true) { 
String t = JOptionPane.showInputDialog(null,"1,添加 ;\n2,显示;\n3,删除;\n4,查找;\n5,修改;\n6,排序;\n7,退出");
int tt = Integer.parseInt(t);
switch (tt) {
case 1:
add();
break;
case 2:
show();
break;
case 3:
del();
break;
case 4:
find();
break;
case 5:
update();
break;
case 6:
sort();
break;
case 7:
exit();
break;
default:
JOptionPane.showMessageDialog(null, "请输入1到7");
break;
}
}
}

/**
* 登陆
* @return
*/
public static boolean DengLu(){
for (int i = 0; i < 3; i++) {
String s = JOptionPane.showInputDialog(null,"请输入用户名");
String s1 = JOptionPane.showInputDialog(null,"请输入密码");
if (s.equals("冷凌云")  && s1.equals("1314520")) {
return true;
}else{
JOptionPane.showMessageDialog(null, "密码或账号错误,还可以输入"+(2-i)+"次");
}
}
return false;
}


/**
* 添加
*/
public static void add(){
String d= JOptionPane.showInputDialog(null,"请问你要输入几个数据?");
int s = Integer.parseInt(d);
for (int i = 0; i < s; i++) {
saveDate(num);
num++;
}
String v = JOptionPane.showInputDialog(null,"是否显示?y/n");
if (v.equals("y")) {
show();
}
}
/**
*显示
*/
public static void show(){

String x = "姓名          学号          成绩\n";
for (int i = 0; i < num; i++) {
x += name[i]+"                  "+XueHao[i]+"                  "+ChengJi[i]+"\n";
}
JOptionPane.showMessageDialog(null, x);
}
/**
* 删除
*/
public static void del(){
int index = finder();
if (index != -1) {
for (int i = index; i < num-1; i++) {
name[i] = name[i+1];
XueHao[i] = XueHao[i+1];
ChengJi[i] = ChengJi[i+1];
}
num = num-1;
}else{
JOptionPane.showMessageDialog(null, "查无此人");
}
show();
}

/**
* 查找
*/
public static void find(){
int index = finder();
if (index != -1) {
JOptionPane.showMessageDialog(null, "在第"+(index+1)+"个");
show();
}else{
JOptionPane.showMessageDialog(null, "查无此人");
}
}
/**
* 修改
*/
public static void update(){
int index = finder();
if (index != -1) {
saveDate(index);
}
}

public static void saveDate(int a){
String ss = JOptionPane.showInputDialog(null,"请输入名字");
String dd = JOptionPane.showInputDialog(null,"请输入学号");
String aa = JOptionPane.showInputDialog(null,"请输入成绩");

name[a] = ss;
XueHao[a] = Integer.parseInt(dd);
ChengJi[a] = Integer.parseInt(aa);
}
/**
* 排序
*/
public static void sort(){
String s = JOptionPane.showInputDialog(null,"1,成绩排序;\n2学号排序");
int ss = Integer.parseInt(s);
if (ss == 1) {
sort1(ChengJi);
show();
}else{
sort1(XueHao);
show();
}
}
/**
* 把排序那里提取出来
* @param a
*/
public static void sort1(int[] a){
for (int k = 0; k <num; k++) {
for (int p = k+1; p < num; p++) {
if (a[k] > a[p]) {

int temp = ChengJi[k];
ChengJi[k] = ChengJi[p];
ChengJi[p] = temp;

String tem = name[k];
name[k] = name[p];
name[p] = tem;

int te = XueHao[k];
XueHao[k] = XueHao[p];
XueHao[p] = te;
}
}
}
}
/**
* 查找名字返回一个int类型的数字;
* @return
*/
public static int finder(){
String s = JOptionPane.showInputDialog(null,"请输入你要执行的名字");
for (int i = 0; i < num; i++) {
if (s.equals(name[i])) {
return i;
}
}
JOptionPane.showMessageDialog(null, "查无此人");
return -1;
}

public static void exit(){
JOptionPane.showMessageDialog(null, "谢谢使用冷凌云客服端,再见!");
System.exit(0);
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值