形参和实参调用方法

import javax.swing.JOptionPane;

public class Studentone {
public int code;
public String name;
public int grade;


}

/** 主界面 */
public class Studentfor {
public static Studentone[] stu = new Studentone[20];
public static int number = 0;


public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "欢迎光临学生管理系统");
boolean island = login();
while (true) {
if (island == true) {
String s = JOptionPane.showInputDialog(null,
"1、添加\n2、显示\n3、查找\n4、删除\n5、修改\n6、排序\n7、退出\n");
int x = Integer.parseInt(s);
switch (x) {
case 1:
tianjia();
break;
case 2:
xianshi();
break;
case 3:
shanchu();

break;
case 4:
chazhao();
break;
case 5:
xiugai();
break;
case 6:
paixu();
break;
case 7:
JOptionPane.showMessageDialog(null, "请退出系统");
System.exit(0);
break;

default:
JOptionPane.showMessageDialog(null, "请输入1-7");
                   break;
}
}
}


}


/** 排序 */
public static void paixu() {
for (int i = 0; i < number; i++) {
for (int j = i + 1; j < number; j++) {
if (stu[i].grade < stu[j].grade) {
Studentone s = stu[i];
stu[i] = stu[j];
stu[j] = s;
}


}
}
xianshi();
}


/** 修改 */
public static void xiugai() {
int index = findbyname();
if (index != -1) {
String code = JOptionPane.showInputDialog(null, "请输入学号");
String name = JOptionPane.showInputDialog(null, "请输入姓名");
String grade = JOptionPane.showInputDialog(null, "请输入成绩");
Studentone s = new Studentone();
s.code = Integer.parseInt(code);
s.name = name;
s.grade = Integer.parseInt(grade);


}


}


/** 删除 */
public static void shanchu() {
int index = findbyname();
if (index != -1) {
}
for (int i = index; i < number - 1; i++) {
stu[i].code = stu[i + 1].code;
stu[i].name = stu[i + 1].name;
stu[i].grade = stu[i + 1].grade;
}
xianshi();
}


/** 查找 */
public static void chazhao() {
int index = findbyname();
if (index != -1) {
JOptionPane.showMessageDialog(null, "学号 姓名 成绩\n" + stu[index].code
+ " " + stu[index].name + " " + stu[index].grade);


}
xianshi();
}


/** 找出学生下标 */
public static int findbyname() {


String name = JOptionPane.showInputDialog(null, "请输入学生姓名");
for (int i = 0; i < number; i++) {
if (name.equals(stu[i].name)) {
return i;


}


}
JOptionPane.showMessageDialog(null, "无此人");
return -1;
}


/** 显示 */
public static void xianshi(){
String str = "学号  姓名 成绩\n";
for (int i = 0; i < number; i++) {
str += stu[i].code + " " + stu[i].name + " " + stu[i].grade + "\n";


}
JOptionPane.showMessageDialog(null, str);
}


/** 添加 */
public static void tianjia() {
String code = JOptionPane.showInputDialog(null, "请输入学号");
String name = JOptionPane.showInputDialog(null, "请输入姓名");
String grade = JOptionPane.showInputDialog(null, "请输入成绩");
Studentone s = new Studentone();
s.code = Integer.parseInt(code);
s.name = name;
s.grade = Integer.parseInt(grade);
number++;
}


/** 登录 */
public static boolean login() {
String x = JOptionPane.showInputDialog(null, "请输入用户名");
String y = JOptionPane.showInputDialog(null, "请输入密码");
if (x.equals("123") && y.equals("456")) {
JOptionPane.showMessageDialog(null, "登录成功");
return true;
} else {
JOptionPane.showMessageDialog(null, "用户名和密码错误");
return false;
}
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值