Student类:
package com.exercise.bean; import lombok.*; import java.util.Arrays; /** * @Author:Zxb * @Version:1.0 * @Date:2022/11/22-9:50 * @Since:jdk1.8 * @Description: */ @Setter @Getter @AllArgsConstructor @NoArgsConstructor public class Student { //学号,姓名,性别,班级,多门成绩信息 private int stuId; private String name; private String stuSex; private String stuClass; private Score[] scores; @Override public String toString() { return "Student{" + "stuId=" + stuId + ", name='" + name + '\'' + ", stuSex='" + stuSex + '\'' + ", stuClass='" + stuClass + '\'' + '}'; } }
Score类:
package com.exercise.bean; import lombok.*; /** * @Author:Zxb * @Version:1.0 * @Date:2022/11/22-9:57 * @Since:jdk1.8 * @Description: */ @Setter @Getter @AllArgsConstructor @NoArgsConstructor @ToString public class Score { //成绩编号,科目,分数 private int scoreId; private String subject; private int number; }
StudentAction类:显示菜单
package com.exercise.action; import com.exercise.bean.Score; import com.exercise.bean.Student; import com.exercise.service.StudentService; import com.exercise.service.impl.StudentServiceImpl; import java.util.Scanner; /** * @Author:Zxb * @Version:1.0 * @Date:2022/11/22-9:50 * @Since:jdk1.8 * @Description: */ public class StudentAction { //扫描仪 private static Scanner scanner=new Scanner(System.in); //一组学生 private static Student[] students =new Student[3]; //业务对象 private static StudentService studentService =new StudentServiceImpl(); static{ //第一个学生 //成绩列表 Score[] scores1=new Score[2]; scores1[0] =new Score(1,"语文",80); scores1[1] =new Score(2,"数学",90); students[0]=new Student(101,"tom","男","java",scores1); //第二个学生 //成绩列表 Score[] scores2 = new Score[3]; scores2[0] = new Score(3, "语文", 70); scores2[1] = new Score(4, "数学", 88); scores2[2] = new Score(5, "英语", 100); students[1] = new Student(102, "cat", "女", "JAVA1班", scores2); //第三个学生 //成绩列表 Score[] scores3 = new Score[3]; scores3[0] = new Score(6, "语文", 79); scores3[1] = new Score(7, "数学", 89); scores3[2] = new Score(8, "英语", 100); students[2] = new Student(103, "lucy", "女", "JAVA1班", scores3); } /** * 启动菜单 */ public static void startMenu(){ boolean b=true; while(b){ System.out.println("********欢迎使用成绩管理系统*********"); System.out.println("\t\t1、查找成绩信息"); System.out.println("\t\t2、统计成绩信息"); System.out.println("\t\t3、显示学生信息"); System.out.println("\t\t0、退出系统"); System.out.println("请选择:"); int choose=scanner.nextInt(); switch (choose){ case 1: studentService.findScore(students,scanner); break; case 2: studentService.countScore(students,scanner); break; case 3: studentService.showStudent(students); break; case 0: System.out.println("谢谢使用,系统已退出!"); b=false; break; } } } }
StudentService:接口
package com.exercise.service; import com.exercise.bean.Student; import java.util.Scanner; /** * @Author:Zxb * @Version:1.0 * @Date:2022/11/22-9:51 * @Since:jdk1.8 * @Description: */ public interface StudentService { /** * 查找成绩信息 * @param students * @param scanner */ void findScore(Student[] students, Scanner scanner); /** * 统计成绩信息 * @param students * @param scanner */ void countScore(Student[] students,Scanner scanner); /** * 显示学生信息 * @param students */ void showStudent(Student[] students); }
StudentServiceImpl:实现
package com.exercise.service.impl; import com.exercise.bean.Score; import com.exercise.bean.Student; import com.exercise.service.StudentService; import java.util.Scanner; /** * @Author:Zxb * @Version:1.0 * @Date:2022/11/22-10:08 * @Since:jdk1.8 * @Description: */ public class StudentServiceImpl implements StudentService { @Override public void findScore(Student[] students, Scanner scanner) { System.out.println("请输入要查询的学生学号:"); int inputId = scanner.nextInt(); //根据编号查找对应的成绩信息 Score[] scores = getScoreById(students, inputId); //先判断 if (scores == null) { System.out.println("查找失败,该学生没有参加考试!"); return; } //成绩信息 for (Score score : scores) { System.out.println(score); } } @Override public void countScore(Student[] students, Scanner scanner) { System.out.println("请输入要统计的学生编号:"); int inputId = scanner.nextInt(); //根据编号查找对应的成绩信息 Score[] scores = getScoreById(students, inputId); //先判断 if (scores == null) { System.out.println("统计失败,该学生没有参加考试"); return; } //及格门数以及总成绩 int count = 0, sum = 0; for (Score score : scores) { if (score.getNumber() >= 60) { count++; } //累加和 sum += score.getNumber(); } System.out.println("及格门数:" + count + "\t总成绩为:" + sum); } @Override public void showStudent(Student[] students) { for (Student student : students) { System.out.println(student); //学生对应的成绩 Score[] scores = student.getScores(); for (Score score : scores) { System.out.println(score); } System.out.println("-----------"); } } /** * 根据学生编号查找成绩信息 * * @param students * @param id * @return */ private Score[] getScoreById(Student[] students, int id) { for (Student student : students) { if (id == student.getStuId()) { return student.getScores(); } } return null; } }
StudentTest:
package com.exercise.test; import com.exercise.action.StudentAction; import com.exercise.bean.Student; /** * @Author:Zxb * @Version:1.0 * @Date:2022/11/22-9:51 * @Since:jdk1.8 * @Description: */ public class StudentTest { /** * 启动 * @param args */ public static void main(String[] args) { StudentAction.startMenu(); } }
原文地址:http://www.cnblogs.com/19981206-zxb/p/16914445.html
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,请务用于商业用途!
3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员!
8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载
声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性