package bate;
import java.io.*;
import java.util.*;
//创建学生类
class Student {
int idex;
String name;
double score1, score2, score3;
double e = (score1 + score2 + score3) / 3;
//构造函数
Student(int idex, String name, double score1, double score2, double score3,
double e) {
this.idex = idex;
this.name = name;
this.score1 = score1;
this.score2 = score2;
this.score3 = score3;
this.e = e;
}
public void print() {
System.out.println(idex + " " + name + " " + score1 + " " + score2
+ " " + score3 + " " + e);
}
}
//创建类
class Q {
int idex;
String name;
double score1, score2, score3;
double e = (score1 + score2 + score3) / 3;
Vector<Student> student = new Vector<Student>();
Student s = new Student(idex, name, score1, score2, score3, e);
//创建输入方法
void input() {
Scanner ss = new Scanner(System.in);
System.out.println("输入学生数");
int ii = ss.nextInt();
for (int i = 0; i < ii; i++) {
Scanner sc = new Scanner(System.in);
System.out.println("输入学生学号");
this.idex = sc.nextInt();
System.out.println("输入学生姓名");
this.name = sc.next();
System.out.println("输入语文成绩");
this.score1 = sc.nextDouble();
System.out.println("输入数学成绩");
this.score2 = sc.nextDouble();
System.out.println("输入英语成绩");
this.score3 = sc.nextDouble();
e = (score1 + score2 + score3) / 3;
student.addElement(new Student(idex, name, score1, score2, score3,
e));
}
}
//输出方法
void print1() {
if (student.size() == 0) {
System.out.println("没有学生信息,请输入信息");
} else {
System.out.println("学号" + " " + "姓名" + " " + "语文" + " " + "数学"
+ " " + "英语" + " " + "平均成绩");
for (int i = 0; i < student.size(); i++) {
((Student) student.elementAt(i)).print();
}
}
}
//排序方法
void order() {
Scanner sc = new Scanner(System.in);
System.out.println("输入对应数字的操作1:按平均成绩排序。2:按学号排序。3:按语文成绩排序。"
+ "4:按数学成绩排序。5:按英语成绩排序");
int j = sc.nextInt();
switch (j) {
//按平均成绩排序
case 1: {
for (int i = 0; i < student.size() - 1; i++) {
for (int k = 0; k < student.size() - i - 1; k++) {
double t = ((Student) student.get(k)).e;
double y = ((Student) student.get(k + 1)).e;
if (t < y) {
Student paixu;
paixu = (Student) student.get(k);
student.set(k, student.get(k + 1));
student.set(k + 1, paixu);
}
}
}
System.out.println("排序后");
System.out.println("学号" + " " + "姓名" + " " + "语文" + " " + "数学"
+ " " + "英语" + " " + "平均成绩");
for (int i = 0; i < student.size(); i++) {
((Student) student.elementAt(i)).print();
}
break;
}
//按学号排序
case 2: {
for (int i = 0; i < student.size() - 1; i++) {
for (int k = 0; k < student.size() - i - 1; k++) {
double t = ((Student) student.get(k)).idex;
double y = ((Student) student.get(k + 1)).idex;
if (t < y) {
Student paixu;
paixu = (Student) student.get(k);
student.set(k, student.get(k + 1));
student.set(k + 1, paixu);
}
}
}
System.out.println("排序后");
System.out.println("学号" + " " + "姓名" + " " + "语文" + " " + "数学"
+ " " + "英语" + " " + "平均成绩");
for (int i = 0; i < student.size(); i++) {
((Student) student.elementAt(i)).print();
}
break;
}
//按语文成绩排序
case 3: {
for (int i = 0; i < student.size() - 1; i++) {
for (int k = 0; k < student.size() - i - 1; k++) {
double t = ((Student) student.get(k)).score1;
double y = ((Student) student.get(k + 1)).score1;
if (t < y) {
Student paixu;
paixu = (Student) student.get(k);
student.set(k, student.get(k + 1));
student.set(k + 1, paixu);
}
}
}
System.out.println("排序后");
System.out.println("学号" + " " + "姓名" + " " + "语文" + " " + "数学"
+ " " + "英语" + " " + "平均成绩");
for (int i = 0; i < student.size(); i++) {
((Student) student.elementAt(i)).print();
}
break;
}
//按數學成績排序
case 4: {
for (int i = 0; i < student.size() - 1; i++) {
for (int k = 0; k < student.size() - i - 1; k++) {
double t = ((Student) student.get(k)).score2;
double y = ((Student) student.get(k + 1)).score2;
if (t < y) {
Student paixu;
paixu = (Student) student.get(k);
student.set(k, student.get(k + 1));
student.set(k + 1, paixu);
}
}
}
System.out.println("排序后");
System.out.println("学号" + " " + "姓名" + " " + "语文" + " " + "数学"
+ " " + "英语" + " " + "平均成绩");
for (int i = 0; i < student.size(); i++) {
((Student) student.elementAt(i)).print();
}
break;
}
//按英语成绩排序
case 5: {
for (int i = 0; i < student.size() - 1; i++) {
for (int k = 0; k < student.size() - i - 1; k++) {
double t = ((Student) student.get(k)).score3;
double y = ((Student) student.get(k + 1)).score3;
if (t < y) {
Student paixu;
paixu = (Student) student.get(k);
student.set(k, student.get(k + 1));
student.set(k + 1, paixu);
}
}
}
System.out.println("排序后");
System.out.println("学号" + " " + "姓名" + " " + "语文" + " " + "数学"
+ " " + "英语" + " " + "平均成绩");
for (int i = 0; i < student.size(); i++) {
((Student) student.elementAt(i)).print();
}
break;
}
default: {
System.out.println("重新输入对应数字");
}
}
}
//创建搜索方法
void search() {
if (student.size() == 0) {
System.out.println("没有学生信息,请输入信息");
} else {
boolean a = true;
while (a) {
Scanner s = new Scanner(System.in);
System.out.println("按数字操作1:按学号查询;2:按姓名查询");
int w = s.nextInt();
switch (w) {
//按学号查询
case 1: {
Scanner sc = new Scanner(System.in);
System.out.println("输入学生学号");
int i = sc.nextInt();
for (int j = 0; j < student.size(); j++) {
if (i == ((Student) student.get(j)).idex) {
((Student) student.elementAt(j)).print();
}
if (j == student.size()&&i !=((Student) student.get(j)).idex) {
System.out.println("没有此学生");
}
}
System.out.println("是否继续查找?继续请按 1,其它操作请按任意数字键。");
Scanner ss = new Scanner(System.in);
int b = ss.nextInt();
if (b == 1) {
a = true;
} else {
a = false;
}
break;
}
//按姓名查询
case 2: {
Scanner sc = new Scanner(System.in);
System.out.println("输入学生姓名");
String i = sc.next();
for (int j = 0; j < student.size(); j++) {
if (i.equals(((Student) student.get(j)).name)) {
((Student) student.elementAt(j)).print();
} else {
if (j == student.size()
&& !i.equals(((Student) student.get(j)).name)) {
System.out.println("没有此学生");
}
}
}
System.out.println("是否继续查找?继续请按 1,其它操作请按任意数字键。");
Scanner ss = new Scanner(System.in);
int b = ss.nextInt();
if (b == 1) {
a = true;
} else {
a = false;
}
break;
}
default: {
System.out.println("重新输入对应数字");
}
}
}
}
}
//删除学生类
void delete() {
if (student.size() == 0) {
System.out.println("没有学生信息,请输入信息");
} else {
boolean a = true;
while (a) {
Scanner s = new Scanner(System.in);
System.out.println("按照数字操作1:按学号查询要删除的学生;2:按姓名查询要删除的学生");
int w = s.nextInt();
switch (w) {
//按学号找学生
case 1: {
Scanner sc = new Scanner(System.in);
System.out.println("输入学生学号");
int i = sc.nextInt();
for (int j = 0; j < student.size(); j++)
评论0