8月11日总结
来源:互联网 发布:上证50指数成分股数据 编辑:程序博客网 时间:2024/05/17 09:08
在方法调用时,传递和返回对象,传递和返回的是对象的引用。
final Man m=new Man(); 在创建对象时,如果加上final,表示m这个变量的引用不能改变。也就是说,m不能再指向i别的对象。但是m所指向对象的属性是可以改变的。
今天在讲了类和对象后,又重新做了一边学生管理系统这个项目,更加的简便。
import javax.swing.JOptionPane;
public class Studentmanage {
// 学生的人数
public static int number = 0;
// 连接学生对象
public static Student[] stur = new Student[20];
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "欢迎进入学生管理系统");
boolean island = Login();
if (island == false) {
JOptionPane.showMessageDialog(null, "非法用户");
System.exit(0);
}
while (true) {
String s = JOptionPane.showInputDialog(null,
"1、添加\n2、显示\n3、删除\n4、查找\n5、修改\n6、排序\n7、退出");
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:
update();
break;
case 6:
sort();
break;
case 7:
System.exit(0);
;
default:
JOptionPane.showMessageDialog(null, "请输入1-7之间的数");
break;
}
}
}
/**
* 添加
*/
public static void add() {
String code = JOptionPane.showInputDialog(null, "请输入学生的学号");
String name = JOptionPane.showInputDialog(null, "请输入学生的姓名");
String grade = JOptionPane.showInputDialog(null, "请输入学生的成绩");
stur[number] = new Student();
stur[number].code = Integer.parseInt(code);
stur[number].name = name;
stur[number].grade = Integer.parseInt(grade);
number++;
show();
}
/**
* 显示
*/
public static void show() {
String str = "学号 姓名 成绩\n";
for (int i = 0; i < number; i++) {
str += stur[i].code + " " + stur[i].name + " "
+ stur[i].grade + "\n";
}
JOptionPane.showMessageDialog(null, str);
}
/**
* 删除
*/
public static void del() {
int index = findbyname();
if (index != -1) {
for (int i = index; i < number - 1; i++) {
stur[index] = stur[index + 1];
}
number--;
show();
}
}
/**
* 查找
*/
public static void find() {
int index = findbyname();
if (index != -1) {
JOptionPane.showMessageDialog(null, "学号 " + stur[index].code
+ " " + "姓名 " + stur[index].name
+ "成绩 " + stur[index].grade);
}
}
/**
* 修改
*/
public static void update() {
int index = findbyname();
if (index != -1) {
String code = JOptionPane.showInputDialog(null, "请重新输入学生的学号");
stur[index].code = Integer.parseInt(code);
String name = JOptionPane.showInputDialog(null, "请重新输入学生的姓名");
stur[index].name = name;
String grade = JOptionPane.showInputDialog(null, "请重新输入学生的成绩");
stur[index].grade = Integer.parseInt(grade);
show();
}
}
/**
* 排序
*/
public static void sort() {
JOptionPane.showMessageDialog(null, "学生成绩从大到小排列为");
for (int i = 0; i < number; i++) {
for (int j = i + 1; j < number; j++) {
if (stur[i].grade < stur[j].grade) {
Student s = stur[i];
stur[i] = stur[j];
stur[j] = s;
}
}
}
show();
}
/**
* 找出输入学生的下标
*/
public static int findbyname() {
int index = -1;
String s = JOptionPane.showInputDialog(null, "请输入学生的姓名");
for (int i = 0; i < number; i++) {
if (s.equals(stur[i].name)) {
index = i;
return index;
}
}
JOptionPane.showMessageDialog(null, "查无此人");
return -1;
}
/**
* 登陆
*/
public static boolean Login() {
for (int i = 0; i < 3; i++) {
String username = JOptionPane.showInputDialog(null, "请输入用户名");
String pwd = JOptionPane.showInputDialog(null, "请输入密码");
if (username.equals("123") && pwd.equals("456")) {
JOptionPane.showMessageDialog(null, "登陆成功");
return true;
} else {
JOptionPane.showMessageDialog(null, "账号或密码错误,请重新输入");
}
}
return false;
}
}
- 8月11日总结
- 8月11日总结
- 【11月8日】排序算法总结
- 8月8日总结
- 11月6日总结
- 3月11日总结
- 11月19日总结
- 11月27日 总结
- 11月29日 总结
- 8月5日总结
- 8月10日总结
- 8月7日总结
- 8月13日总结
- 8月1日总结
- 8月2日总结
- 8月3日总结
- 8月4日总结
- 8月5日总结
- Git版本库(1)
- NOIP 2011 day1 选择客栈
- 文件大小转换
- 关于C语言中的字符指针和字符数组
- 【HDOJ 5379】 Mahjong tree
- 8月11日总结
- 协方差的理解
- C++ 编译过程
- hdu 2001 计算两点间的距离
- 黑马程序员
- hdoj 1875 畅通工程再续 【最小生成树】
- Android开发之QQ直接登陆功能
- CentOS 7 虚拟机创建失败
- 【bzoj1208】[HNOI2004]宠物收养所