发布网友 发布时间:2022-04-25 22:29
共1个回答
热心网友 时间:2022-06-18 04:38
摘要List subsA = new ArrayList();subsA.add(yuwenA);subsA.add(shuxueA);subsA.add(yingyuA);List subsB = new ArrayList();subsB.add(yuwenB);subsB.add(shuxueB);subsB.add(yingyuB);List subsC = new ArrayList();subsC.add(yuwenC);subsC.add(shuxueC);subsC.add(yingyuC);List subsD = new ArrayList();subsD.add(yuwenD);subsD.add(shuxueD);subsD.add(yingyuD);Student sutA = new Student("A", subsA);Student sutB = new Student("B", subsB);Student sutC = new Student("C", subsC);Student sutD = new Student("D", subsD);//下面是具体的算法;List stus = new ArrayList();stus.add(sutA);stus.add(sutB);stus.add(sutC);stus.add(sutD);for (int i = 0; i < stus.size(); i++) {Student stu = stus.get(i);List sub = stu.getSubs();int sumChenji = 0;for (int j = 0; j < sub.size(); j++) {sumChenji += sub.get(j).getChenji();}System.out.println("同学" + stu.getName() + "的三科平均成绩为" + sumChenji / sub.size());}List yuwenSub = new ArrayList();List shuxueSub = new ArrayList();Lis咨询记录 · 回答于2021-11-03Java+没门课程只记录最高分,按课程字典序输出成绩单您好,很高兴为您服务。正在为您咨询相关信息,马上回复您!package com.sun.test;import java.util.List;public class Student {private String name; //学生姓名private List subs;// 学生成绩public Student(String name,List subs){this.name = name;this.subs = subs;}public String getName() {return name;}public void setName(String name) {this.name = name;}public List getSubs() {return subs;}public void setSubs(List subs) {this.subs = subs;}}(2)学科636f70793231313335323631343130323136353331333332633065类package com.sun.test;public class Subject {private String subName; //学科名称private int chenji;//学科成绩 整数型public String getSubName() {return subName;}public void setSubName(String subName) {this.subName = subName;}public int getChenji() {return chenji;}public void setChenji(int chenji) {this.chenji = chenji;}public Subject(String subName,int chenji){this.subName = subName;this.chenji = chenji;}}(3)比较实现类package com.sun.test;import java.util.Comparator;public class SubJectCom implements Comparator {@Overridepublic int compare(Object o1, Object o2) {Subject s1 = null, s2 = null;if (o1 instanceof Subject) {s1 = (Subject) o1;}if (o2 instanceof Subject) {s2 = (Subject) o2;}if (s1.getChenji() < s2.getChenji())return 1;if (s1.getChenji() > s2.getChenji())return -1;return 0;}}(4)最后的处理类,包含学生成绩初始化,学生初始化,以及最后的对应处理逻辑package com.sun.test;import java.util.ArrayList;import java.util.Collections;import java.util.List;public class Test {/*** @param args*/public static void main(String[] args) {Subject yuwenA = new Subject("语文", 90);Subject yuwenB = new Subject("语文", 75);Subject yuwenC = new Subject("语文", 80);Subject yuwenD = new Subject("语文", 95);Subject shuxueA = new Subject("数学", 99);Subject shuxueB = new Subject("数学", 66);Subject shuxueC = new Subject("数学", 88);Subject shuxueD = new Subject("数学", 44);Subject yingyuAList subsA = new ArrayList();subsA.add(yuwenA);subsA.add(shuxueA);subsA.add(yingyuA);List subsB = new ArrayList();subsB.add(yuwenB);subsB.add(shuxueB);subsB.add(yingyuB);List subsC = new ArrayList();subsC.add(yuwenC);subsC.add(shuxueC);subsC.add(yingyuC);List subsD = new ArrayList();subsD.add(yuwenD);subsD.add(shuxueD);subsD.add(yingyuD);Student sutA = new Student("A", subsA);Student sutB = new Student("B", subsB);Student sutC = new Student("C", subsC);Student sutD = new Student("D", subsD);//下面是具体的算法;List stus = new ArrayList();stus.add(sutA);stus.add(sutB);stus.add(sutC);stus.add(sutD);for (int i = 0; i < stus.size(); i++) {Student stu = stus.get(i);List sub = stu.getSubs();int sumChenji = 0;for (int j = 0; j < sub.size(); j++) {sumChenji += sub.get(j).getChenji();}System.out.println("同学" + stu.getName() + "的三科平均成绩为" + sumChenji / sub.size());}List yuwenSub = new ArrayList();List shuxueSub = new ArrayList();Lis