咱就是说,这玩意好难,我捣鼓了一宿,有没有人帮我看看这个eclipse的
private static String[] stuNames = { "张三丰", "郭靖", "乔峰", "张无忌", "杨过" };
private static String[] courses = { "JAVA", "C++", "Oracle", "Android" };
private static int[][] sorces = { { 87, 76, 63, 98 }, { 67, 79, 83, 75 }, { 90, 76, 65, 60 }, { 84, 88, 63, 79 },
{ 72, 66, 58, 77 } };
@SuppressWarnings("resource")
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String tip = "请输入以下指令:\n1、查询某门课程的平均分\n2、查询某位学生总分\n3、按照某门课程的成绩排序 输出\n"
+ "4、查询某位剩下的某门课程的成绩\n5、退出程序";
System.out.println(tip);
boolean flag = true;
while (flag) {
int n = sc.nextInt();
switch (n) {
case 1:
System.out.println("请输入课程名称:");
Scanner sc1 = new Scanner(System.in);
String cName = sc1.nextLine();
double avg = avg(cName);
System.out.println(cName+"课程平均分数为:" + avg);
break;
case 2:
System.out.println("请输入学生姓名:");
Scanner sc2 = new Scanner(System.in);
String uName = sc2.nextLine();
double sum = sum(uName);
System.out.println("学生"+uName+"总分数为:" + sum);
break;
case 3:
System.out.println("请输入课程名称:");
Scanner sc3 = new Scanner(System.in);
String couName3 = sc3.nextLine();
sort(couName3);
break;
case 4:
System.out.println("请输入学生姓名:");
Scanner sc4 = new Scanner(System.in);
String stuName = sc4.nextLine();
System.out.println("请输入课程名称:");
String couName = sc4.nextLine();
double score = get(stuName, couName);
System.out.println("学生"+stuName+"的"+couName+"课程分数为:"+score);
break;
case 5:
System.exit(0);
break;
}
System.out.println("是否继续操作?(y/n)");
Scanner sc5 = new Scanner(System.in);
String no = sc5.nextLine();
if ("y".equals(no)) {
flag = true;
System.out.println(tip);
} else {
flag = false;
}
}
}
public static double avg(String cName) {
double avg = 0;
int num = -1;
for (int i = 0; i < courses.length; i++) {
if (cName.equals(courses[i])) {
num = i;
}
}
for (int j = 0; j < sorces.length; j++) {
if (num >= 0) {
avg += sorces[j][num];
}
}
return avg / sorces.length;
}
// 查询学生总分
public static double sum(String uName) {
double sum = 0;
int num = -1;
for (int i = 0; i < stuNames.length; i++) {
if (uName.equals(stuNames[i])) {
num = i;
}
}
for (int j = 0; j < courses.length; j++) {
if (num >= 0) {
sum += sorces[num][j];
}
}
return sum;
}
public static void sort(String cName) {
int num = -1;
for (int i = 0; i < courses.length; i++) {
if (cName.equals(courses[i])) {
num = i;
}
}
List<Integer> arr = new ArrayList<Integer>();
for (int j = 0; j < sorces.length; j++) {
if (num >= 0) {
arr.add(sorces[j][num]);
}
}
arr.sort((a1, a2) -> {
if (a1 > a2) {
return -1;
} else {
return 1;
}
});
System.out.println(arr);
}
public static double get(String uName, String cName) {
int x = -1;
int y = -1;
double score = 0;
for (int i = 0; i < stuNames.length; i++) {
if (uName.equals(stuNames[i])) {
x = i;
}
}
for (int i = 0; i < courses.length; i++) {
if (cName.equals(courses[i])) {
y = i;
}
}
if (x >= 0 && y >= 0) {
score = sorces[x][y];
}
return score;
}