用java学生成绩统计import java.util.Scanner;
public class Test {
protected static boolean end_flag = true;
public static void main(String[] args) {
Students student = new Students();
student.InputData();// 输入学生数据
String order;
while (end_flag) {
System.out.println("请输入数字1-5:");
Scanner s = new Scanner(System.in);
order = s.nextLine();
student.Operator(order);
}
}
}
Students类:
import java.util.ArrayList;
import java.util.Scanner;
public class Students {
private int STUDENTS_NUM = 5; // 学生的人数
private int SUBJECTS_NUM = 3; // 课程数
private String[][] data = https://www.04ip.com/post/new String[STUDENTS_NUM][SUBJECTS_NUM + 2];
private String name;
private int Chinese_score;
private int Math_score;
private int English_score;
public void SearchHighestScore(String[][] original) { // 查找最高成绩
int flag = Integer.parseInt(original[0][4]), position = 0;
for (int i = 1; ioriginal.length; i++) {
if (Integer.parseInt(original[i][4])flag) {
flag = Integer.parseInt(original[i][4]);
position = i;
}
}
System.out.print("最高分同学的姓名和总分为:");
System.out.println(original[position][0] + " " + original[position][4]);
}
public void SearchLowestScore(String[][] original) {
int flag = Integer.parseInt(original[0][4]), position = 0;
for (int i = 1; ioriginal.length; i++) {
if (Integer.parseInt(original[i][4])flag) {
flag = Integer.parseInt(original[i][4]);
position = i;
}
}
System.out.print("最低分同学的姓名和总分为:");
System.out.println(original[position][0] + " " + original[position][4]);
}
public void OrderStudents(String[][] original) {
String[][] result = original;
String temp;
for (int i = 1; iresult.length; i++) {
for (int j = 0; jresult.length - i; j++) {
if (Integer.parseInt(result[j][4])Integer
.parseInt(result[j + 1][4])) {
temp = result[j][4];
result[j][4] = result[j + 1][4];
result[j + 1][4] = temp;
temp = result[j][0];
result[j][0] = result[j + 1][0];
result[j + 1][0] = temp;
}
}
}
System.out.println("排名\t" + "姓名\t" + "总分\t");
for (int i = 0; iSTUDENTS_NUM; i++) {
System.out.println(i + 1 + "\t" + result[i][0] + "\t"
+ result[i][4]);
}
}
public void ScoreUnder60(String[][] original) {
System.out.println("平均分在60以下的学生的姓名为:");
ArrayList temp = new ArrayList();
for (int i = 0; ioriginal.length; i++) {
if (Integer.parseInt(original[i][4]) / SUBJECTS_NUM60) {
temp.add(original[i][0]);
}
}
System.out.print(temp + " ");
System.out.println("\n" + "平均分在60以下的学生的人数为:"
+ temp.size());
}
public Integer SearchScore(String student_name) {
int position = -1;
for (int i = 0; idata.length; i++) {
if (student_name.equals(data[i][0])) {
position = i;
}
}
if (position != -1)
return Integer.valueOf(data[position][4]);
else
return null;
}
public void Operator(String order) {
if ("1".equals(order)) {
SearchHighestScore(data);
SearchLowestScore(data);
} else if ("2".equals(order)) {
OrderStudents(data);
} else if ("3".equals(order)) {
ScoreUnder60(data);
} else if ("4".equals(order)) {
String name;
System.out.println("请输入学生的姓名:");
Scanner s = new Scanner(System.in);
name = s.nextLine();
if (SearchScore(name) != null)
System.out.println(name + "的总分为:" + SearchScore(name));
else
System.out.println("查无此人");
推荐阅读
- 清苑网红直播,清苑网红女人物
- 公众号推荐阅读外引的简单介绍
- 官方公众号怎么申请,公众号申请教程
- word如何拆分多行,word一行拆分多行
- JAVA输出对应星期代码 java输入星期几的第一个字母
- 鲁大师怎么查硬盘使用多久,鲁大师怎么看硬盘用了多久
- 湖南林业gis公共服务平台,湖南林业科学院
- 如何微信多开安卓手机,安卓微信多开方法
- mysql时间怎么查看 mysql怎么查看自己的密码