student类
package stu_zizhu;
public class student {
private int id;
private String name;
private int age;
private int score;
private int avg;
private int math;
private int chinese;
private int english;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public int getAvg() {
return avg;
}
public void setAvg(int avg) {
this.avg = avg;
}
public int getMath() {
return math;
}
public void setMath(int math) {
this.math = math;
}
public int getChinese() {
return chinese;
}
public void setChinese(int chinese) {
this.chinese = chinese;
}
public int getEnglish() {
return english;
}
public void setEnglish(int english) {
this.english = english;
}
public student(int id, String name, int age, int score, int avg, int math, int chinese, int english) {
super();
this.id = id;
this.name = name;
this.age = age;
this.score = score;
this.avg = avg;
this.math = math;
this.chinese = chinese;
this.english = english;
}
public student() {
super();
}
}
测试类test
package stu_zizhu;
import java.util.Scanner;
import stu_system1.Stu;
public class test {
static student[] stu=new student[100];
static int number=0;
static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
int choice=0;
while(true) {
System.out.println("欢迎使用学生管理系统!");
System.out.println("1.添加学生信息:");
System.out.println("2.查看学生信息:");
System.out.println("3.删除学生信息:");
System.out.println("4.修改学生信息:");
System.out.println("6.输入exit退出学生系统");
System.out.println("请输入操作:");
choice=sc.nextInt();
switch(choice){
case 1: add(); break;//添加学生信息
case 2: show();break;//查询学生信息
case 3: delete();break;//修改学生信息
case 4: change();break;//删除学生信息
case 5: paixu();break;//对学生信息排序
case 6: exit(); break;
default:
break;
}
}
}
private static void add() {
while(true) {
System.out.println("按任意键开始录入信息!!!录入信息完毕请输入0");
if(sc.nextInt()==0) {
break;
}
System.out.println("请输入学生基本信息");
stu[number]=new student();
System.out.println("请输入学生ID");
stu[number].setId(sc.nextInt());
System.out.println("请输入学生NAME");
stu[number].setName(sc.next());
System.out.println("请输入学生AGE");
stu[number].setAge(sc.nextInt());
System.out.println("请输入学生CHINESE");
stu[number].setChinese(sc.nextInt());
System.out.println("请输入学生MATH");
stu[number].setMath(sc.nextInt());
System.out.println("请输入学生ENGLISH");
stu[number].setEnglish(sc.nextInt());
number++;
System.out.println("添加成功");
}
}
private static void delete() {
System.out.println("请输入要删除学生信息的ID");
for(int i=0;i<number;i++) {
if(sc.nextInt()==(stu[i].getId())) {
stu[i]=stu[i+1];
number--;
System.out.println("删除成功!");
}
else if(i!=number) {
System.out.println("无此人信息!");
}
}
}
private static void change() {
System.out.println("请输入要修改学生信息的ID");
// Scanner sc1=new Scanner(System.in);
for(int i=0;i<number;i++) {
if(sc.nextInt()==(stu[i].getId())) {
System.out.println("发现了该学生,正在查看学生信息...");
System.out.println("学生原成绩为"+stu[i].getId()+stu[i].getName()+stu[i].getAge());
System.out.print("请输入要修改的学生的信息");
System.out.println("请输入修改后的id:");
Scanner a=new Scanner(System.in);
stu[i].setId(a.nextInt());
System.out.println("请输入修改后的name:");
Scanner b=new Scanner(System.in);
stu[i].setName(b.next());
System.out.println("请输入修改后的age:");
Scanner c=new Scanner(System.in);
stu[i].setAge(c.nextInt());
System.out.println("请输入修改后的chinese:");
Scanner d=new Scanner(System.in);
stu[i].setChinese(d.nextInt());
System.out.println("请输入修改后的math:");
Scanner e=new Scanner(System.in);
stu[i].setMath(e.nextInt());
System.out.println("请输入修改后的english:");
Scanner f=new Scanner(System.in);
stu[i].setEnglish(f.nextInt());
break;
}
if(i==number) {
System.out.println("无此人信息!");
}
}
}
// Scanner sc2=new Scanner(System.in);
// stu[i].setStuNum(scanner.next());
/*
* System.out.println("发现了该学生,正在修改...");
System.out.println("学生原成绩为"+StudentList.get(j).getGrade());
System.out.print("请输入修改后学生的成绩:");
Scanner Ggrade = new Scanner(System.in);
int grade2 = Ggrade.nextInt();
StudentList.get(j).setGrade(grade2);
System.out.println("修改成功!!!");
*/
// System.out.println("请输入要修改的学生的信息");
// if(sc1.nextInt()(stu[i].getId())) {
// stu[i].setId(sc.nextInt());
// }else {
// System.out.println("输入错误! 请输入要修改学生信息字段");
// }
// if(sc1.next().equals(stu[i].getName())) {
// stu[i].setName(sc.next());
// }else {
// System.out.println("输入错误! 请输入要修改学生信息字段");
// }
// if(sc1.nextInt()(stu[i].getAge())) {
// stu[i].setAge(sc.nextInt());
// }else {
// System.out.println("输入错误! 请输入要修改学生信息字段");
// }
// if(sc1.nextInt()(stu[i].getMath())) {
// stu[i].setMath(sc.nextInt());
// }else {
// System.out.println("输入错误! 请输入要修改学生信息字段");
// }
// if(sc1.nextInt()(stu[i].getChinese())) {
// stu[i].setChinese(sc.nextInt());
// }else {
// System.out.println("输入错误! 请输入要修改学生信息字段");
// }
// if(sc1.nextInt()==(stu[i].getEnglish())) {
// stu[i].setEnglish(sc.nextInt());
// }else {
// System.out.println("输入错误! 请输入要修改学生信息字段");
// }
// break;
//
// }
private static void show() {
System.out.println("学生信息为:");
System.out.println("id "+" "+"name "+" "+"age"+" "+"chinese"+" "+"math"+" "+"english"+" ");
for(int i=0;i<number;i++) {
System.out.println(stu[i].getId()+" "+stu[i].getName()+" "+" "+stu[i].getAge()+" "+" "+stu[i].getChinese()+" "+" "+stu[i].getMath()+" "+stu[i].getEnglish());
}
System.out.println();
}
private static void paixu() {
// TODO Auto-generated method stub
}
private static void exit() {
System.out.println("感谢您的使用!");
System.exit(0);
}
}